title: Sending large files with XSockets.Net
body: <p>I am very much new to XSockets in .Net.</p>
  
  <p>Following is my Server Code.</p>
  
  <pre><code>public class MyChatController : XSocketController
  {
  
      public void Foo(ITextArgs textArgs)
      {
          this.SendToAll(textArgs);
      }
  
  }
  </code></pre>
  
  <p>Following is Client side Code</p>
  
  <pre><code>   static void Main(string[] args)
      {
          var client = new XSocketClient("ws://127.0.0.1:4502/MyChat","*");
  
          client.OnOpen += (sender, eventArgs) =&gt; Console.WriteLine("OPEN");
          client.Bind("foo", message=&gt;
          {
              dynamic data = Newtonsoft.Json.JsonConvert.DeserializeObject(message.data);
  
              var array = data;
  
              byte[] bytes = Convert.FromBase64String(array);
  
              Stream readStream = new MemoryStream(bytes);//videovm.video
              var fileName = "C:\\Users\\NandaKishore\\Documents\\Visual Studio 2013\\Projects\\CSClientApp\\CSClientApp\\somefile" + ".mp4";
  
              string targetPath =  fileName;
  
              FileStream writeStream = new FileStream(targetPath, FileMode.Create, FileAccess.Write);
  
              int Length = 256;
              Byte[] buffer = new Byte[Length];
              int bytesRead = readStream.Read(buffer, 0, Length);
              while (bytesRead &gt; 0)
              {
                  writeStream.Write(buffer, 0, bytesRead);
                  bytesRead = readStream.Read(buffer, 0, Length);
              }
              readStream.Close();
              writeStream.Close();
  
              Console.WriteLine("done dona done");
          });
          client.Open();
  
  
  
  
  
          ConsoleKeyInfo cki;            
          Console.WriteLine("Press the Escape (Esc) key to quit and any other key to send a message: \n");
  
          var _FileName = "C:\\Users\\NandaKishore\\Documents\\Visual Studio 2013\\Projects\\CSClientApp\\CSClientApp\\tt.mp4";
  
          byte[] _Buffer = null;
          try
          {
              System.IO.FileStream _FileStream = new System.IO.FileStream(_FileName, System.IO.FileMode.Open, System.IO.FileAccess.Read);
              System.IO.BinaryReader _BinaryReader = new System.IO.BinaryReader(_FileStream);
              long _TotalBytes = new System.IO.FileInfo(_FileName).Length;
              _Buffer = _BinaryReader.ReadBytes((Int32)_TotalBytes);
              _FileStream.Close();
              _FileStream.Dispose();
              _BinaryReader.Close();
          }
          catch (Exception _Exception)
          {
              Console.WriteLine("Exception caught in process: {0}", _Exception.ToString());
          }
  
          do
          {
              cki = Console.ReadKey();
              if (cki.Key != ConsoleKey.Escape) {
  
                  var dd = Convert.ToBase64String(_Buffer);
                  client.Send(dd, "foo");
              }
          } while (cki.Key != ConsoleKey.Escape);
      }
  </code></pre>
  
  <p>It works fine for small images and videos but with large video it fails. Is there a better way to pass large files such as byte serving or anything.</p>
  
  <p>Any guidance would be helping.</p>