Winsock 2: Sends and Recv's

So at the moment I have coded a sever which uses select() to find active sockets, reads from them and then takes the data recv'd and sends it back out to all connected clients appart from the sender.
I have a talker which just spits out hello to the server.
The problem I have is that when I call recv on the client, the client just hangs. I can see that the client connects to the server and everything seems fine. I can get data flowing to the server and out of the server but I cant seem to get it recv'ed by the client.
I can use telnet as a client and it seems to work fine with the server. all sends and recv's get to the right places.


Here is the code I have for the program recving. the output of the program is just
"Reciver: In For loop"
And then it hangs.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
      for(;;)
       {
             cout << "Reciver: In For loop\n";

	          if((Bytes_Rcvd = recv(mySocket,p, sizeof rcv,0)) <= 0)
	          {
                            cout << "Error!\n";
              
             }
           else
           {
                   rcv[Bytes_Rcvd+1] = '\0;
	           cout << "Recived message : " << rcv;
	           cout << "/t# of Bytes: " << Bytes_Rcvd << "\n";
            }
       } 
I suggest looking at the sender side. Apart from the syntax error on line 12 (which I assume is a cut-paste
error and that this code actually compiles), the receiver code looks OK. (I assume p is a pointer to
rcv[0], but even if not, you should at least see some output from line 13).
The I have quite throughly, its a fairly simple loop which loops select for incoming connections / data, processes the connection, then sends the data on.
The reason I don't think it is server side is because as I said before. If I start the server and connect with telnet from two other machines sending and reciving from each machine works.
p is a pointer to rcv.
(and yeh I noticed ln12 after I hit compile )
I think recv() might block until it completely fills up the buffer you give it...how big is rcv?
really? That might explain it, rcv is 256 chars. I'm only sending 5 chars each time. so maybe I should just leave it running overnight and have a look see in the morning to see if there is any change.
Problem solved, I think i didnt initialise the buffer properly on all clients, it seems to work perfectly now.
Topic archived. No new replies allowed.