Java Code Examples for com.badlogic.gdx.net.Socket#getOutputStream()
The following examples show how to use
com.badlogic.gdx.net.Socket#getOutputStream() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BNLS.java From riiablo with Apache License 2.0 | 6 votes |
private boolean QueryRealms(Socket socket) throws IOException { FlatBufferBuilder builder = new FlatBufferBuilder(); int[] realms = new int[REALMS.length]; for (int i = 0; i < REALMS.length; i++) { realms[i] = Realm.createRealm(builder, builder.createString(REALMS[i][0]), builder.createString(REALMS[i][1])); } int realmsVec = QueryRealms.createRealmsVector(builder, realms); QueryRealms.startQueryRealms(builder); QueryRealms.addRealms(builder, realmsVec); int realmId = QueryRealms.endQueryRealms(builder); int id = com.riiablo.net.packet.bnls.BNLS.createBNLS(builder, BNLSData.QueryRealms, realmId); builder.finish(id); ByteBuffer data = builder.dataBuffer(); OutputStream out = socket.getOutputStream(); WritableByteChannel channel = Channels.newChannel(out); channel.write(data); Gdx.app.log(TAG, "returning realms list..."); return false; }
Example 2
Source File: MCP.java From riiablo with Apache License 2.0 | 5 votes |
private boolean ConnectionDenied(Socket socket, String reason) throws IOException { FlatBufferBuilder builder = new FlatBufferBuilder(); int reasonOffset = builder.createString(reason); int connectionDeniedId = ConnectionClosed.createConnectionClosed(builder, reasonOffset); int id = com.riiablo.net.packet.mcp.MCP.createMCP(builder, MCPData.ConnectionClosed, connectionDeniedId); builder.finish(id); ByteBuffer data = builder.dataBuffer(); OutputStream out = socket.getOutputStream(); WritableByteChannel channel = Channels.newChannel(out); channel.write(data); return true; }
Example 3
Source File: MCP.java From riiablo with Apache License 2.0 | 5 votes |
private boolean ConnectionAccepted(Socket socket) throws IOException { Gdx.app.debug(TAG, "Connection accepted!"); FlatBufferBuilder builder = new FlatBufferBuilder(); ConnectionAccepted.startConnectionAccepted(builder); int connectionAcceptedId = ConnectionAccepted.endConnectionAccepted(builder); int id = com.riiablo.net.packet.mcp.MCP.createMCP(builder, MCPData.ConnectionAccepted, connectionAcceptedId); builder.finish(id); ByteBuffer data = builder.dataBuffer(); OutputStream out = socket.getOutputStream(); WritableByteChannel channel = Channels.newChannel(out); channel.write(data); return false; }
Example 4
Source File: MCP.java From riiablo with Apache License 2.0 | 5 votes |
private void StartInstance(CreateGame createGame, ResponseListener listener) { Gdx.app.debug(TAG, "Requesting game instance for " + createGame); FlatBufferBuilder builder = new FlatBufferBuilder(); StartInstance.startStartInstance(builder); int startInstanceOffset = StartInstance.endStartInstance(builder); int id = MSI.createMSI(builder, MSIData.StartInstance, startInstanceOffset); builder.finish(id); ByteBuffer data = builder.dataBuffer(); Socket socket = null; try { socket = Gdx.net.newClientSocket(Net.Protocol.TCP, "localhost", com.riiablo.server.mcp.MSI.PORT, null); OutputStream out = socket.getOutputStream(); WritableByteChannel channelOut = Channels.newChannel(out); channelOut.write(data); buffer.clear(); buffer.mark(); InputStream in = socket.getInputStream(); ReadableByteChannel channelIn = Channels.newChannel(in); channelIn.read(buffer); buffer.limit(buffer.position()); buffer.reset(); MSI packet = MSI.getRootAsMSI(buffer); Gdx.app.log(TAG, "packet type " + MCPData.name(packet.dataType())); listener.handleResponse(packet); } catch (Throwable t) { listener.failed(t); } finally { if (socket != null) socket.dispose(); } }
Example 5
Source File: MSI.java From riiablo with Apache License 2.0 | 5 votes |
private boolean StartInstance(Socket socket, com.riiablo.net.packet.msi.MSI packet) throws IOException { Gdx.app.debug(TAG, "Starting instance..."); try { File outFile = new File("D2GS.tmp"); ProcessBuilder processBuilder = new ProcessBuilder("java", "-jar", "server/d2gs/build/libs/d2gs-1.0.jar"); processBuilder.redirectOutput(ProcessBuilder.Redirect.to(outFile)); processBuilder.redirectError(ProcessBuilder.Redirect.to(outFile)); Process process = processBuilder.start(); instances.add(process); } catch (Throwable t) { Gdx.app.error(TAG, t.getMessage(), t); } int ip = 2130706433; // 127.0.0.1 short port = 6114; FlatBufferBuilder builder = new FlatBufferBuilder(); StartInstance.startStartInstance(builder); StartInstance.addResult(builder, Result.SUCCESS); StartInstance.addIp(builder, ip); StartInstance.addPort(builder, port); int startInstanceOffset = StartInstance.endStartInstance(builder); int id = com.riiablo.net.packet.msi.MSI.createMSI(builder, MSIData.StartInstance, startInstanceOffset); builder.finish(id); ByteBuffer data = builder.dataBuffer(); OutputStream out = socket.getOutputStream(); WritableByteChannel channel = Channels.newChannel(out); channel.write(data); Gdx.app.debug(TAG, "Returning instance at " + InetAddress.getByAddress(ByteBuffer.allocate(4).putInt(ip).array())); return true; }
Example 6
Source File: BNLS.java From riiablo with Apache License 2.0 | 5 votes |
private boolean ConnectionDenied(Socket socket, String reason) throws IOException { FlatBufferBuilder builder = new FlatBufferBuilder(); int reasonOffset = builder.createString(reason); int connectionDeniedId = ConnectionClosed.createConnectionClosed(builder, reasonOffset); int id = com.riiablo.net.packet.bnls.BNLS.createBNLS(builder, BNLSData.ConnectionClosed, connectionDeniedId); builder.finish(id); ByteBuffer data = builder.dataBuffer(); OutputStream out = socket.getOutputStream(); WritableByteChannel channel = Channels.newChannel(out); channel.write(data); return true; }
Example 7
Source File: BNLS.java From riiablo with Apache License 2.0 | 5 votes |
private boolean ConnectionAccepted(Socket socket) throws IOException { Gdx.app.debug(TAG, "Connection accepted!"); FlatBufferBuilder builder = new FlatBufferBuilder(); ConnectionAccepted.startConnectionAccepted(builder); int connectionAcceptedId = ConnectionAccepted.endConnectionAccepted(builder); int id = com.riiablo.net.packet.bnls.BNLS.createBNLS(builder, BNLSData.ConnectionAccepted, connectionAcceptedId); builder.finish(id); ByteBuffer data = builder.dataBuffer(); OutputStream out = socket.getOutputStream(); WritableByteChannel channel = Channels.newChannel(out); channel.write(data); return false; }