Oh hai guise.
So I don't really know a lot of java,but I've been trying to make a server for my flash game.
I've been basing it heavily on the example here :How to make a multi-client Flash Java server | Broculos.net
I remember back when I worked with GameMaker and 39dll, I could write bytes and stuff in order in a buffer, and send that buffer to multiple clients.
I've managed to make it work sending strings, and using string manipulation, but I'm trying to get it right with sending integers and strings.
So far I have this.
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ /** * * @author Fricken Hamster */ import java.net.*; import java.io.*; public class GameServerConnection extends Thread { protected Socket socket; protected BufferedReader socketIn; protected PrintWriter socketOut; protected GameServer server; protected String clientName; protected int slotId; protected String slotIdString; public GameServerConnection( Socket socket, GameServer server) { this.socket = socket; this.server = server; } public SocketAddress getRemoteAddress() { return this.socket.getRemoteSocketAddress(); } protected void debug( String str) { ACityMain.debug(str); } public void run() { try { this.socketIn = new BufferedReader( new InputStreamReader( this.socket.getInputStream())); this.socketOut = new PrintWriter(this.socket.getOutputStream() , true); this.slotIdString = Integer.toString(this.slotId); if ( slotIdString.length() < 2) { slotIdString = "0" + slotIdString; } //this.server.writeToAll( "01" + slotIdString ); this.server.writeToAll( 1 , this.slotId , ""); //String line = this.socketIn.readLine(); //System.out.println(line); int header = this.socketIn.read(); System.out.print(header); //while( line != null ) while (header != 0) { debug("recieved from " + this.clientName + ": " + header); //int header = Integer.parseInt(line.substring(0, 2)); //String body = line.substring(2,line.length()); //String newLine; String body; switch (header) { case 2: body = this.socketIn.readLine(); this.clientName = body; //newLine = "02" + this.slotIdString + body; //this.server.writeToAll(newLine); this.server.writeToAll(header, this.slotId, body); //debug("read 2"); break; case 9: if( this.server.remove(this.slotId)) { this.finalize(); return; } break; case 10: //newLine = "10" + this.slotIdString + body; body = this.socketIn.readLine(); this.server.writeToAll(header, this.slotId, body); //newLine); break; } //line = this.socketIn.readLine(); } } catch( Exception e) { debug( "Run Error:" + e.getMessage()); } } public void write( int header , int id , String msg) { try { this.socketOut.write(header); this.socketOut.write(id); this.socketOut.write(msg + "\u0000"); //this.socketOut.write(msg + "\u0000"); this.socketOut.flush(); } catch( Exception e) { debug( "Write Error:" + e.getMessage()); } } protected void finalize() { try { this.socketIn.close(); this.socketOut.close(); this.socket.close(); debug("connection closed at " + this.getRemoteAddress()); } catch( Exception e) { debug( "Finalize Error:" + e.getMessage()); } } }
Can anyone help me, or point me towards some examples/documentation of what I neeD? Thanks!