PDA

Click to See Complete Forum and Search --> : Networking in java


daveyboy
Mar 26th, 2002, 06:36 PM
A while ago I created a Draughts game using swing (was only 2 players), and I've decided to update it, so that you can play over a network....

I have a basic knowledge of the networking side, I'd be able to create Sockets, and use streams to pass objects or strings to and from the two clients, but my question is this:

How do I start up the client, allow it to poll for another client waiting for a game, and then after a time delay let it sit and wait for another client to poll for it?

I was thinking about broadcasting and awaiting a response, and then waiting for someone else to broadcast...

Does anyone have any suggestions????? (examples of code would be warmly welcomed!!!)

honeybee
Apr 10th, 2002, 04:13 AM
For one thing, you have to put the sockets in threads, so you don't waste your time polling for input.

Another thing is it would be better to have a permanent server on the net that has a static IP address, and put a Java app (or any other app) there listening on a specific port. This server could act as a meeting place for potential clients. Each client could query this server and get details (specifically the IP address and port) of any other client waiting for a game. The clients could then connect with each other and proceed with the game.

I am sorry, but I can't give you any code, as I don't have any practical coding experience in Java.

.