M Maloney wrote:
> Thanks for your help. So you need to put a socket in the client and
> sever? And if I wanted to connect to a server on the net I'd just use
> the Inet.getAddressByName(...) method for the particular site on both
> client and server?
You only need the getAddressByName functionality on the client since,
once the server gets the data, some of the included information is the
address of the client.
The server opens a UDP socket and listens for data. The code s = new
DatagramSocket(9800); says to create a socket on port 9800. UDP is
connectionless - meaning that you don't have to establish a connection;
you just send data or listen on the port for data to arrive. So when we
write s.receive(p); on the server, it blocks and waits for data to arrive.
The client needs to know two things: the server ip and the port. The
first thing we do is get a socket. Since the client can tell the server
what port it is using, we can just accept whatever default port we get
(depends on socket implementation, essentially random). We then call
connect with an ip address and use the port number that the server is
listening on. Once we have a "connection" (that is, our datagramsocket
knows where to send the data), we can send out our request (and wait for
a response, if we like).
I hope I haven't confused you with my explanation

.
--
Peter MacMillan
e-mail/msn: