![]() ![]() And you have to specify the server’s address and port in the DatagramPacket. nd(request) As you can see, the buffer has no data because QOTD service doesn’t require a client sends any specific message. InetAddress address = InetAddress.getByName(hostname) ĭatagramSocket socket = new DatagramSocket() ĭatagramPacket request = new DatagramPacket(buffer, buffer.length, address, port) The following code snippet sends a DatagramPacket to a server specified by hostname and port: String hostname = "" Java UDP Client ExampleWe will write code for a client program that requests for quotes from a server that implements the Quote of the Day (QOTD) service - an Internet standard. Consult the DatagramSocket Javadoc for full details.Now, let’s see some sample programs in action. These methods can throw IOException, PortUnreachableException, SocketTimeoutException… so you have to catch or re-throw them. If the timeout expires, a SocketTimeoutException is raised.
0 Comments
Leave a Reply. |