XML Sockets?
Useful for transferring data between multiple clients connected to a server. And after much tweaking I have something. You could test this code locally like me but unfortunately I could not get it working online.
Here goes anyhow:
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 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | import java.io.*; import java.net.*; public class simpleServer { public static void main(String args[]) { // Message terminator char EOF = (char)0x00; try { // create a serverSocket connection on port 9999 ServerSocket s = new ServerSocket(9999); System.out.println("Server started. Waiting for connections ..."); // wait for incoming connections Socket incoming = s.accept(); BufferedReader data_in = new BufferedReader(new InputStreamReader(incoming.getInputStream())); PrintWriter data_out = new PrintWriter(incoming.getOutputStream()); data_out.println("Welcome! type EXIT to quit." + EOF); data_out.flush(); boolean quit = false; // Waits for the EXIT command while (!quit) { String msg = data_in.readLine(); if (msg == null) quit = true; if (!msg.trim().equals("EXIT")) { data_out.println("You sayed: <b>" + msg.trim() + "</b>" + EOF); data_out.flush(); } else { quit = true; } } } catch (Exception e) { System.out.println("Connection lost"); } } } |
It’s important to note that I did not create this but it is a server connection using java…
and you should head to http://www.stormation.info/2010/11/java/ if you can’t remember the basics.
And now the flash:
READ MORE »
