Skip to main content
gamedev.net
🔒 Locked

TCP socket problem

Started by Kotumo Mar 31, 2004 at 4:54 AM 1 replies 350+ views
Original Post
Kotumo
Kotumo
Hi, What I would like to have is a client sending data to a server now and then on the client''s initiative. This part I understand, but I also need to have the server to be able to send data to the client whenever the server wants to. Would I need to open two socket connections for this to work? I''ve tried to set up a sort of request/response system, but then the server would have to wait for the client to send first. I need to be able to send both ways whenever I want to. Btw, I''m programming this in Java. Thanks.
onebeer
onebeer
TCP sockets are bi-directional. That is, the server and the client can both send data to the other using one socket. Just because one connects and the other listens does not affect what can be sent.

The problem I see is how to handle the data reads and writes. You might want to search the forums for people talking about synchronous vs asynchronous connections. In my systems (non-game) that use TCP/IP, I use seperate threads to handle the sockets. The main thread then can put a packet in a queue and the socket thread sends the data. Also, the socket thread can wait for data and put it in a queue when found. The main thread can check the queue as needed, without blocking.

Again, look through the forums. Many other people have had this problem.


- onebeer
onebeer

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.