Created
October 13, 2014 00:01
-
-
Save hiroshiro/2f040c0c025fa7840871 to your computer and use it in GitHub Desktop.
myclient.java simple test
This file contains hidden or 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.*; | |
import java.net.*; | |
/** | |
* myclient | |
*/ | |
public class myclient { | |
private static final String SERVER_HOST = "localhost"; | |
private static final int SERVER_PORT = 9000; | |
public static void main(String[] args) { | |
if (args.length < 1) { | |
System.err.println("usage: java " + myclient.class.getSimpleName() + " message"); | |
System.exit(-1); | |
} | |
Socket sock = null; | |
try{ | |
sock = new Socket(SERVER_HOST, SERVER_PORT); | |
Reader in = new BufferedReader(new InputStreamReader(sock.getInputStream())); | |
Writer out = new BufferedWriter(new OutputStreamWriter(sock.getOutputStream())); | |
for (String arg : args) { | |
out.write(arg); | |
} | |
out.write('.'); // End | |
out.flush(); | |
char[] buf = new char[4096]; | |
while (in.read(buf) != -1) { | |
System.out.println(buf); | |
} | |
} catch (IOException e){ | |
e.printStackTrace(); | |
} finally{ | |
try{ | |
if (sock != null) { | |
sock.close(); | |
} | |
} catch (IOException e) {} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment