Skip to content

Instantly share code, notes, and snippets.

@benek
Created June 13, 2013 17:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benek/5775456 to your computer and use it in GitHub Desktop.
Save benek/5775456 to your computer and use it in GitHub Desktop.
Very simple socket client...
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;
public class SocketClient {
public static void main(String[] args) throws IOException {
Socket socket = new Socket("127.0.0.1", 3550);
PrintWriter output = new PrintWriter(socket.getOutputStream(), true);
BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
BufferedReader stdIn = new BufferedReader(new InputStreamReader(System.in));
String userInput;
while((userInput = stdIn.readLine()) != null){
output.println(userInput);
System.out.println("echo: " + input.readLine());
}
output.close();
input.close();
stdIn.close();
socket.close();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment