Reputation: 1566
client side coding
TcpClient tcpclnt = new TcpClient("192.157.1.1", 8001);
Stream stm = tcpclnt.GetStream();
byte[] bites = new byte[dataLength];
// assigning values for bites
stm.Write(clientdata, 0, clientdata.Length);
Server side Coding
TcpListener listener = new TcpListener(IPAddress.Any, 8001);
listener.Start(10);
Socket soc = listener.AcceptSocket();
byte[] bites = new byte[1000];
int avail = soc.Available;
int receivedBytesLen = soc.Receive(bites);
After writting the clientdata on stream also In server side soc.Available is zero. So server can't read the data. What is the problem?
Upvotes: 1
Views: 2919
Reputation: 3299
NetworkStream.Flush() is actually not implemented 'yet' in .net 4.0 as per msdn:
Flushes data from the stream. This method is reserved for future use.
Your problem is probably being caused by the nagle algorithm, prevent small amounts of data being sent to reduce congestion. You could try disabling it by setting the following properties on your tcpClient object:
tcpClient.NoDelay = true;
tcpClient.Client.NoDelay = true;
Also checkout networkComms.net which is a ready to use solution if you keep having problems.
Upvotes: 2
Reputation: 273784
The data is buffered. The client hast to Write more. Or close the stream.
Upvotes: 2
Reputation: 18306
after stm.Write(...)
add a call stm.Flush()
so the data will be flushed to the network.
Upvotes: -2