import java.io.*;
import java.net.*;
public class Server
{
public static void main(String args[]) {
try{
ServerSocket ss = new ServerSocket(8842) ;
while(true) {
Socket s = ss.accept() ;
DataInputStream dos = new DataInputStream(s.getInputStream()) ;
System.out.println(dos.readUTF()) ;
}
}catch(Exception e) {
e.printStackTrace() ;
}
}
}
import java.net.* ;
import java.io.* ;
public class Client
{
public static void main(String args[]) {
try{
Socket s = new Socket("localhost",8842) ;
OutputStream os = s.getOutputStream() ;
DataOutputStream dos = new DataOutputStream(os) ;
dos.writeUTF("Connect a server!") ;
dos.flush() ;
dos.close() ;
os.close() ;
s.close() ;
}catch(Exception e) {
e.printStackTrace() ;
}
}
}