Socket programming: sending and receiving msgs back and forth
Hi all,
I have a server which is used by number of client Apps. Now when a client initiates a sendto request to a server it has to respond(after recvfrom) by sending a message using sendto back to client and this should be done back and forth. What I dont understand is, does the client have to open a new port to receive packets from client? If yes, then how will server know to what port of the client(assuming server ports are well-known to clients)? I had given up on sending messages back and forth using UDP and switched to TCP. I could send a read and write message back and forth. But the trouble comes when I have more than one client wanting to talk to server using SOCK_STREAM. The first one gets through but the second client seems to get blocked forever(but I got no error upon socket creation or upon connect with the server on the same port as the previous client).. Can somebody throw some light?? Thanks for the help. |
Show us the code!
If you're doing something along the lines of: Code:
client_sock = accept(listen_sock, ...); |
Here is the client code:
Code:
//this is from header file |
And here is the server code(UDP)
Code:
|
I was actually reading about select(). Is select to allow multiple sockets between server and client? But then, to have it working, should we know the number of clients talking to a server? That somehow sounds so wrong :( :(
|
All times are GMT -5. The time now is 02:37 AM. |