View Single Post
  #3 (permalink)  
Old 10-15-2008, 07:29 AM
hunterbdb hunterbdb is offline
Member
 
Join Date: Oct 2008
Posts: 33
hunterbdb is on a distinguished road
//------------------------------------------------------------------------
public void run() {

socket = new DatagramSocket(1985);
while(b)
{

//receive message from client.
byte[] buf = new byte[100];
DatagramPacket packet1 = new DatagramPacket(buf,buf.length);
socket.receive(packet1);


//declare string message.
String message = new String(packet1.getData(),0 ,packet.getLength());

//declare bytes for return message.
byte[] buf2 = new byte[100];
buf2 = message.getBytes();

//get address and port from packet1.
InetAddress address = packet1.getAddress();
int port = packet1.getPort();
DatagramPacket packet2 = new DatagramPacket(buf2,buf2 .length,address,port);

//send packet2.
socket.send(packet2);



}
socket.close();


}
//------------------------------------------------------------------------

This is my server- with the try and catch statements omitted, because they make it messy and confusing to analyze.
It is in a thread.

yes, basic...but its what I need for my messenger at the moment.

any ideas on how I would make this multi client?
Reply With Quote