Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Problem Sending Message from SERVER to CLIENT

Problem Sending Message from SERVER to CLIENT

Scheduled Pinned Locked Moved C#
helpcsharpsysadminquestion
8 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    muhammad_umair
    wrote on last edited by
    #1

    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

    M 1 Reply Last reply
    0
    • M muhammad_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

      M Offline
      M Offline
      monstale
      wrote on last edited by
      #2

      Hi, could you please send code, how client receives messages? Would help us, to help you. ;-) bye

      M 1 Reply Last reply
      0
      • M monstale

        Hi, could you please send code, how client receives messages? Would help us, to help you. ;-) bye

        M Offline
        M Offline
        muhammad_umair
        wrote on last edited by
        #3

        //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(); }

        M 1 Reply Last reply
        0
        • M muhammad_umair

          //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(); }

          M Offline
          M Offline
          monstale
          wrote on last edited by
          #4

          looks like a sending code. You used NetworkStream.Write(). That might be the problem. :-)

          M 1 Reply Last reply
          0
          • M monstale

            looks like a sending code. You used NetworkStream.Write(). That might be the problem. :-)

            M Offline
            M Offline
            muhammad_umair
            wrote on last edited by
            #5

            but i have also used server.send(AnyMessage); this isn't working as well..

            M 1 Reply Last reply
            0
            • M muhammad_umair

              but i have also used server.send(AnyMessage); this isn't working as well..

              M Offline
              M Offline
              monstale
              wrote on last edited by
              #6

              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? ;-)

              M 1 Reply Last reply
              0
              • M monstale

                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? ;-)

                M Offline
                M Offline
                muhammad_umair
                wrote on last edited by
                #7

                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 :)

                J 1 Reply Last reply
                0
                • M muhammad_umair

                  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 :)

                  J Offline
                  J Offline
                  J4amieC
                  wrote on last edited by
                  #8

                  muhammad_umair wrote:

                  newys

                  Syntax error. 'newys' does not exist in the english language.

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups