Skip to content

Instantly share code, notes, and snippets.

@woogieboogie93
Created December 16, 2017 11:21
Show Gist options
  • Select an option

  • Save woogieboogie93/a0a0956b9eb93d8ca0406c28f23ad680 to your computer and use it in GitHub Desktop.

Select an option

Save woogieboogie93/a0a0956b9eb93d8ca0406c28f23ad680 to your computer and use it in GitHub Desktop.
JavaTcpProgramming created by woogie_boogie - https://repl.it/@woogie_boogie/JavaTcpProgramming
import java.io.*;
import java.net.*;
class ClientExample1 {
public static void main(String[] args) {
Socket sock = null;
try {
sock = new Socket("###.###.###.###", 9000);
InputStream in = sock.getInputStream();
OutputStream out = sock.getOutputStream();
String str = "Hello, Server!";
out.write(str.getBytes());
byte arr[] = new byte[100];
in.read(arr);
System.out.println(new String(arr));
}
catch(Exception e) {
System.out.println(e.getMessage());
}
finally {
try {
sock.close();
}
catcn(Exception e) {
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment