C
Chan
A TCP connection to retrieve a customer's order data. While the
sender's sending the same list of order data, say 10 orders, data
picked up from receiving buffer can be different and keep changing.
Further study reveals that the extra orders are duplicated.
I'm using synchronized way, here is my code,
....
client.SetSocketOption(SocketOptionLevel.Socket,
SocketOptionName.SendTimeout, 1000);
client.SetSocketOption(SocketOptionLevel.Socket,
SocketOptionName.ReceiveTimeout, 1000);
try
{
client.Connect(remoteEP);
byte[] byteData = Encoding.ASCII.GetBytes(sbPost.ToString()); //(PostContent);
client.Send(byteData, 0, byteData.Length, SocketFlags.None);
byte[] byteRec = new byte[5000];
int any = client.Receive(byteRec, byteRec.Length, SocketFlags.None);
while (any > 0)
{
response.Append(Encoding.ASCII.GetString(byteRec));
any = client.Receive(byteRec, byteRec.Length,
SocketFlags.None);
}
client.Shutdown(SocketShutdown.Both);
client.Close();
client = null;
return response.ToString();
}
catch (Exception e)
{
throw e;
}
....
sender's sending the same list of order data, say 10 orders, data
picked up from receiving buffer can be different and keep changing.
Further study reveals that the extra orders are duplicated.
I'm using synchronized way, here is my code,
....
client.SetSocketOption(SocketOptionLevel.Socket,
SocketOptionName.SendTimeout, 1000);
client.SetSocketOption(SocketOptionLevel.Socket,
SocketOptionName.ReceiveTimeout, 1000);
try
{
client.Connect(remoteEP);
byte[] byteData = Encoding.ASCII.GetBytes(sbPost.ToString()); //(PostContent);
client.Send(byteData, 0, byteData.Length, SocketFlags.None);
byte[] byteRec = new byte[5000];
int any = client.Receive(byteRec, byteRec.Length, SocketFlags.None);
while (any > 0)
{
response.Append(Encoding.ASCII.GetString(byteRec));
any = client.Receive(byteRec, byteRec.Length,
SocketFlags.None);
}
client.Shutdown(SocketShutdown.Both);
client.Close();
client = null;
return response.ToString();
}
catch (Exception e)
{
throw e;
}
....