hello
i am creating application to send images over socket
on some devices the server receives only part of the packet not all of it
also on some other devices the app is working fine
note that i send the images over the internet not in the internal network
this is the server
the client
i am creating application to send images over socket
on some devices the server receives only part of the packet not all of it
also on some other devices the app is working fine
note that i send the images over the internet not in the internal network
this is the server
C#:
TcpListener listener = new TcpListener(port);
listener.Start();
Socket socket = listener.AcceptSocket();
byte[] data = new byte[4];
int count = socket.Receive(data, SocketFlags.None);
int messagesize = 0;
//could optionally call BitConverter.ToInt32(sizeinfo, 0);
messagesize |= data[0];
messagesize |= (((int)data[1]) << 8);
messagesize |= (((int)data[2]) << 16);
messagesize |= (((int)data[3]) << 24);
int len = 0;
label3.Text = messagesize.ToString();
while(len != messagesize)
{
data = new byte[1024];
len += socket.Receive(data);
label4.Text = len.ToString();
}
the client
C#:
byte[] data = Capture();
TcpClient client = new TcpClient(ip, port);
NetworkStream stream = client.GetStream();
int length = data.Length;
byte[] sizeinfo = new byte[4];
//could optionally call BitConverter.GetBytes(data.length);
sizeinfo[0] = (byte)data.Length;
sizeinfo[1] = (byte)(data.Length >> 8);
sizeinfo[2] = (byte)(data.Length >> 16);
sizeinfo[3] = (byte)(data.Length >> 24);
stream.Write(sizeinfo, 0, sizeinfo.Length);
stream.Write(data, 0, data.Length);
stream.Close();
client.Close();