Created
December 16, 2017 11:21
-
-
Save woogieboogie93/a0a0956b9eb93d8ca0406c28f23ad680 to your computer and use it in GitHub Desktop.
JavaTcpProgramming created by woogie_boogie - https://repl.it/@woogie_boogie/JavaTcpProgramming
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.*; | |
| 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