views:

86

answers:

2

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

EDIT:

  //Code at SERVER for SENDING...
  private void button_send(object sender, EventArgs e)
     { 
        string input = textBoxWrite.Text;
        byte[] SendData = new byte[1024];
        ASCIIEncoding encoding = new ASCIIEncoding();
        SendData = encoding.GetBytes(input);
        client.Send(SendData,SendData.Length,SocketFlags.None);
        textBoxShow.Text = "Server: " + input;
     }
   //Code at CLIENT for receiving
            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();
            }
+1  A: 

I'm not sure how best to help based on the information you've provided, but perhaps you could look at something like this example of C# socket programming and compare with your own application.

DisplacedAussie
A: 

I saw that example before, but im using threading in my Application so if i will use both SEND & RECEIVE on the same method, it hangs my Application..i just want to send a message when ever a button is pressed and all the text written in the textbox sends to client...

Umair