Learning java server technologies, trying to clarify some things. There are few technologies that allow java applications to communicate with each other.
1) Web services (REST/SOAP) over http
2) Simple POST/GET using URLConnection over http.
3) Sockets
4) RMI = Sockets + Object Serialization + Some Utilities
5) Different media servers like red5 = rtmp or rtmpt
All this technologies assume that there is a server application and client application. Client application know server address and should be initiator of call. And as far as I understand there are noway for server to push data to client, he can only send data back as response to client. And It is possible, if only they change their roles, in this case server should know client IP.
So I wondering how does network games work ? Is it possible to open connection and exchange data between server and client for all time without pulling request from client every 1-2 seconds and server would not know client IP. I’m not talking about Comet and other hacks.
Thank you
Most two-way, persistent applications open a network port and keep it open. The server listens on a well-known port, and when a client connects to that port, it gets a persistent TCP connection to the server. A connection like that is basically a bi-directional "pipe", data can flow serially in both directions simultaneously. As long as that pipe is open, the server listens for messages from the client and the client listens for messages from the server.
The common I/O API's used for TCP pipes allow either end of the connection to be "woken up": An asynchronous I/O request executes a registered callback function from a thread managed by the OS or I/O library or the client/server ties up its own thread on a "blocking" call, which returns when data is available. No polling or re-connection attempts are necessary with this model, the client and server both "know" when data is available and can act on it immediately.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With