Java

closed account (N36fSL3A)
Are there any good Java networking tutorials? I'm doing a side project (for a game), and I'm planning on using Java for the server and C++ for the client.

I've decided to do this because I'm starting to dislike C++ for Server-side applications, and I'd figure Java's more fit for the job.
closed account (3hM2Nwbp)
What are your project specs? Java has support for both synchronous and asynchronous models (which are very different beasts).

If you're looking for maximum flexibility, you can take the time to learn the NIO approach.
( http://tutorials.jenkov.com/java-nio/index.html )

Otherwise, plain java.net.* will likely work for you.

If I was designing the system, I'd use a third party library like netty ( http://netty.io/ ) for the server and raw java.net.Sockets for the client.
Last edited on
Have you been to Oracle yet? They have tutorials on most major aspects of Java.
closed account (N36fSL3A)
I'd like to use the UDP datagram.

What are your project specs? Java has support for both synchronous and asynchronous models
Pretty much it needs to handle multiple clients at a time, and I'm looking for the asynchronous model. The server needs to be real-time, as it's for a game.

My server is going to be designed as such -

I have 4 threads. 1 thread receives packets, it decides whether the packet is a duplicate or not based on it's time stamp and header. Then it adds it to a queue. Second thread handles the packets, and when it's done it pops them off the queue. If it needs to, it adds response packets to a send queue. The 3rd, main thread receives input from the server operator, and if it needs to, puts packets on the send queue. The 4th thread sends the packets on the send queue out to the clients.
Last edited on
closed account (3hM2Nwbp)
You could probably consolidate your 3 networking threads into 1 by going with the async model. A single thread should be able to handle many more than 4 connections without even breaking a sweat.
closed account (N36fSL3A)
Yes, but how will I receive console input then? The standard streams are blocking.
Last edited on
closed account (3hM2Nwbp)
You'll still need your main-thread of course. 4 - 3 = 1 :)
closed account (N36fSL3A)
Oh, so you're saying I keep a main thread and a server thread. I understand.
Topic archived. No new replies allowed.