Problem Sending Message from SERVER to CLIENT
-
Hi, im making a Window Application in C# using Socket Programming. I have developed a Server & a Client. Both are working fine but the problem which im gettin is that when ever i send any message from CLIENT, its send perfectly and receives on SERVER but whenever i try to send any message from SERVER it doesn't send to Client, since at the beginning when a connection is built, server sends the message to client that "Connection Established" and received at Client perfectly,but later on server does not send any message to client!!! Could anyone please help me out ??????? Regards Umair
-
Hi, im making a Window Application in C# using Socket Programming. I have developed a Server & a Client. Both are working fine but the problem which im gettin is that when ever i send any message from CLIENT, its send perfectly and receives on SERVER but whenever i try to send any message from SERVER it doesn't send to Client, since at the beginning when a connection is built, server sends the message to client that "Connection Established" and received at Client perfectly,but later on server does not send any message to client!!! Could anyone please help me out ??????? Regards Umair
-
Hi, could you please send code, how client receives messages? Would help us, to help you. ;-) bye
//this is the code at client side for receiving data NetworkStream networkStream = new NetworkStream(server); string input = textBoxUser.Text + ": " + textBoxWrite.Text; ASCIIEncoding encoding = new ASCIIEncoding(); byte[] inputByte = encoding.GetBytes(input); if (networkStream.CanWrite) { networkStream.Write(inputByte, 0, inputByte.Length); textBoxShow.Text = textBoxShow.Text + Environment.NewLine + input; textBoxWrite.Text = ""; networkStream.Flush(); }
-
//this is the code at client side for receiving data NetworkStream networkStream = new NetworkStream(server); string input = textBoxUser.Text + ": " + textBoxWrite.Text; ASCIIEncoding encoding = new ASCIIEncoding(); byte[] inputByte = encoding.GetBytes(input); if (networkStream.CanWrite) { networkStream.Write(inputByte, 0, inputByte.Length); textBoxShow.Text = textBoxShow.Text + Environment.NewLine + input; textBoxWrite.Text = ""; networkStream.Flush(); }
-
looks like a sending code. You used
NetworkStream.Write()
. That might be the problem. :-)but i have also used server.send(AnyMessage); this isn't working as well..
-
but i have also used server.send(AnyMessage); this isn't working as well..
Okay, maybe this a problem in understanding: you wrote code for receiving data at client side, right? You used the method
.Write()
. This method writes bytes to the stream. I think in a receiving method you should use e.g.Read(byte[], int, int)
, or am I wrong? ;-) -
Okay, maybe this a problem in understanding: you wrote code for receiving data at client side, right? You used the method
.Write()
. This method writes bytes to the stream. I think in a receiving method you should use e.g.Read(byte[], int, int)
, or am I wrong? ;-)the problem has been resolved.. the message was not sending for the second time to client because i was using IF loop in client side that would take data from server just once, now on the client side i have replaced if by WHILE(true) and it receives the data until a break is performed send by server in the form of Disconnect..newys thank you guys :)
-
the problem has been resolved.. the message was not sending for the second time to client because i was using IF loop in client side that would take data from server just once, now on the client side i have replaced if by WHILE(true) and it receives the data until a break is performed send by server in the form of Disconnect..newys thank you guys :)