/* Sender.java - the other half */ import java.net.*; import java.io.*; public class Sender extends Thread { public static void main(String[] args) { Sender sender = new Sender(); sender.start(); } public void run() { Socket connection; DataInputStream input; DataOutputStream output; try { connection = new Socket("130.216.34.242", 12774); // my machine // either use the loopback address 127.0.0.1 or the address of the machine // with the receiver. output = new DataOutputStream(connection.getOutputStream()); input = new DataInputStream(connection.getInputStream()); output.writeUTF("Hello from the sender"); String data = input.readUTF(); System.out.println(data); connection.close(); } catch (IOException e) { System.err.println("Sender: " + e); } } }