Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //PROGRAM FOR SERVER SIDE
- /**
- * @Program that Receives a datagram packet from this socket.
- * Receive1.java
- * Author:-RoseIndia Team
- * Date:-20-jun-2008
- */
- import java.io.*;
- import java.net.*;
- import java.util.*;
- public class Receive1 {
- public static void main(String args[])throws Exception {
- DatagramSocket socket = null;
- socket = new DatagramSocket(1313);
- for (int i = 0; i < 10; i++) {
- byte[] buf = new byte[256];
- DatagramPacket packet = new DatagramPacket(buf, buf.length);
- socket.receive(packet);
- buf = new Date().toString().getBytes();
- InetAddress address = packet.getAddress();
- int port = packet.getPort();
- packet = new DatagramPacket(buf, buf.length, address, port);
- socket.send(packet);
- }
- socket.close();
- }
- }
- /*
- //PROGRAM FOR CLIENT SIDE
- /**
- * @Program that Sends a datagram packet from this socket.
- * send1.java
- * Author:-RoseIndia Team
- * Date:-20-jun-2008
- */
- /*
- import java.io.*;
- import java.net.*;
- public class send1 {
- public static void main(String[] args) throws Exception {
- DatagramSocket socket = new DatagramSocket();
- for (int i = 0; i < 10; i++) {
- byte[] buf = new byte[256];
- InetAddress address = InetAddress.getByName("localhost");
- DatagramPacket packet = new DatagramPacket(buf, buf.length, address, 1313);
- socket.send(packet);
- packet = new DatagramPacket(buf, buf.length);
- socket.receive(packet);
- String received = new String(packet.getData());
- System.out.println("Current server time: " + received);
- Thread.sleep(1500);
- }
- socket.close();
- }
- }
- */
Add Comment
Please, Sign In to add comment