I'm trying to use UDP in my game...but I'm having trouble finding good examples...

I'm using DatagramSocket right now for my server and client code. The main thing I'm gettingstuck on is, I have no problem making a serverapp, and client app, and having the client appsend packets to the server. But is there a way for the server app to send stuff back to the client based on the packets sent from the client to the server??

I think more specifically, from the server , I'm trying to find a way to find out where the DatagramPacketis sent from. I tried printing out the InetAddress of the DatagramePacket, but it was of no use.

To my understanding... UDP is not connection base... Do does that mean I can't communicated backand fourth using 1 instance of the UPD protocal?

I'm thinking if I should be using a DatagramChannelon the server implementation instead... But I'mhaving problems locating example code on theinternet. Also I have found serveral posts complainingabout the performance of the DatagramChannel

And advice would be appriciated.Sorry for my amature knowledge in advance.and much thanks.

//packet is the udp-packet the server received from the clientInetAddressaddress = packet.getAddress(); //Gets the clients ip numberintport = packet.getPort(); //get the port the client used to send the upp-packet

//Create a new packet containing data bufpacket = newDatagramPacket(buf, buf.length, address, port);//sending the new packet back to the client.socket.send(packet);

I havn't played around with nio yet but as I understand it, it is a completely new "design" of using sockets. The advantage is that you can don't need one thread for each client connected to your server. This is a big issue with servers that should handle over 1000 client connections at the same time. 1000 thread isn't something that will bost your server preformence exaclty. So if your writting a preformence critical server/client application look in to NIO(or if you just like to learn it) but as you said there is a lack of good documentation. Don't know anything about that book unfortunate.

NIO is good for getting rid of threads, that's right. And yes, that gives better scalability for obscene amounts of clients - but the the absolute best part is avoiding the multithreading code, locking etc. That's why I always use NIO, even though I only expect a few clients on my server (<20).

java-gaming.org is not responsible for the content posted by its members, including references to external websites,
and other references that may or may not have a relation with our primarily
gaming and game production oriented community.
inquiries and complaints can be sent via email to the info‑account of the
company managing the website of java‑gaming.org