Here's the problem: I've successfully setup an app that will pull individual frames of video from a phone and move them to the server. But as you know, the inherent latency won't allow for a smooth transition on the server side. I'm guessing I need to package a number of images in a single byte array and unpack them on the server side. But is there a clean/simple way to do this? Could I use a multi-dimensional array? Something else?
Here's what I got client side (payload is an incoming image converted to a single byte array):
if (_socket != null)
{
SocketAsyncEventArgs socketEventArg = new SocketAsyncEventArgs();
socketEventArg.RemoteEndPoint = _socket.RemoteEndPoint;
socketEventArg.UserToken = null;
socketEventArg.Completed += new EventHandler<SocketAsyncEventArgs>(delegate(object s, SocketAsyncEventArgs e)
{
response = e.SocketError.ToString();
// Unblock the UI thread
_clientDone.Set();
});
socketEventArg.SetBuffer(payload, 0, payload.Length);
_clientDone.Reset();
_socket.SendAsync(socketEventArg);
_clientDone.WaitOne(TIMEOUT_MILLISECONDS);
}
And here's what I'm doing on the server side:
const int portNo = portNumber;
TcpListener listener = new TcpListener(portNo);
listener.Start();
Console.WriteLine("Listening...");
TcpClient tcpClient = listener.AcceptTcpClient();
NetworkStream NWStream = tcpClient.GetStream();
byte[] bytesToRead = new byte[tcpClient.ReceiveBufferSize + 1];
FrameCount += 1;
int numBytesRead = NWStream.Read(bytesToRead, 0, Convert.ToInt32(tcpClient.ReceiveBufferSize));
string FILE_NAME = "c:\\frames\\" + FrameCount.ToString() + ".gif";
System.IO.FileStream fs = null;
fs = new FileStream(FILE_NAME, FileMode.CreateNew, FileAccess.Write);
fs.Write(bytesToRead, 0, numBytesRead);
fs.Close();
tcpClient.Close();
listener.Stop();
StartImage();