D
D
Dmitry Richter2014-05-08 02:55:54
C++ / C#
Dmitry Richter, 2014-05-08 02:55:54

Problem sending data from server to client.C++

Good day. I need to make a chat in c ++, I did half the work and the client sends data to the server, everything is fine, I thought that to send data from the server to the client, just do everything back (that is, on the client, put listening to recv from the server, and on the server send) on the same socket, but something doesn’t work. What will the gurus tell you? How best to do it? (TCP connection)
example of sending from the server

char buf[50] = "";
     int bytesSent;
     if (timer == true) {
      String ^ strT;
      strT = textBox2->Text;
      int TempNumOne = textBox2->Text->Length;
      for (int a = 0; a < TempNumOne; a++)
      {

       buf[a] = strT[a];

      }
      bytesSent = send(s, buf, 50, 0);
      textBox1->Text = "Sent:" + System::Convert::ToString(bytesSent);
      textBox1->Text = "Message :" + textBox2->Text; }


I would like to ask again, I get everything done in 1 socket, I receive and send data, maybe the problem is that you need one to receive, and another to send?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
stream13, 2014-05-08
@stream13

It's not entirely clear from the question what's going on.
Maybe your descriptor is frayed when opening sockets, or handlers are not placed in separate threads.
Also, try replacing server send() with write(socket, data, size).
Perhaps a third example would be helpful.
If possible, I advise you to install WireShark on the client and server, and this will help you dig into the packages.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question