Answer the question
In order to leave comments, you need to log in
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; }
Answer the question
In order to leave comments, you need to log in
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 questionAsk a Question
731 491 924 answers to any question