1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
public static void main(String args[]) { String ip = "192.168.0.2"; int port = 8080; Socket socket = null; OutputStream os = null; OutputStreamWriter osw = null; Socket socket2 = new Socket(); SocketAddress sock_addr = new InetSocketAddress(ip, port); try { socket2.connect(sock_addr); } catch (UnknownHostException ue) { } catch (IOException ie) { } try { os = socket2.getOutputStream(); osw = new OutputStreamWriter(os); } catch (IOException ie) { } String data = "I love you"; try { osw.write(data, 0, data.length()); osw.flush(); } catch (IOException ie) { } } |