Skip to content

Instantly share code, notes, and snippets.

@liuchang0812
Created January 18, 2014 14:16
Show Gist options
  • Save liuchang0812/8491158 to your computer and use it in GitHub Desktop.
Save liuchang0812/8491158 to your computer and use it in GitHub Desktop.
importjava.net.Socket;
importjava.io.IOException;
importjava.io.InputStreamReader;
importjava.io.BufferedReader;
importjava.io.PrintWriter;
publicclassClientTest{
privateSocketsocket;
BufferedReaderin;
PrintWriterout;
publicClientTest(){
try{
System.out.println("Trytoconnectto127.0.0.1:10000");
socket=newSocket("127.0.0.1",10000);
System.out.println("TheServerConnected!");
System.out.println("Pleaseentersomecharacters:");
BufferedReaderline=newBufferedReader(newInputStreamReader(System.in));
out=newPrintWriter(socket.getOutputStream(),true);
out.println(line.readLine());
in=newBufferedReader(newInputStreamReader(socket.getInputStream()));
System.out.println(in.readLine());
out.close();
in.close();
socket.close();
}catch(IOExceptionex){
System.out.println(ex.getMessage());
}
}
publicstaticvoidmain(String[]args){
newClientTest();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment