Created
June 13, 2013 17:08
-
-
Save benek/5775456 to your computer and use it in GitHub Desktop.
Very simple socket client...
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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