You are on page 1of 1

import java.net.*; import java.io.

*; class TcpConnectionClient implements Runnable { Socket socket = null; public TcpConnectionClient() throws Exception{ socket = new Socket("localhost", 20000); Thread th = new Thread(this); th.start(); String msg = null; PrintWriter pw = new PrintWriter(socket.getOutputStream()); while(true) { BufferedReader br = new BufferedReader(new InputStreamR eader(System.in)); msg = br.readLine(); pw.println(msg); pw.flush(); } } public static void main(String[] args) throws Exception { new TcpConnectionClient(); } public void run(){ try{ BufferedReader br = new BufferedReader(new InputStreamReader(so cket.getInputStream())); String msg = null; while(true) { msg = br.readLine(); System.out.println(msg); } }catch (Exception e){ } } }

You might also like