public LogicServer(String host, int port) { injector.mapValue(PacketSender.class, packetSender); injector.mapSingleton(ClientManager.class); HandlerInit.Init(dispatcher, "handler_config.xml"); try { socket.connect(new InetSocketAddress(host, port)); socket.getOutputStream().write(PacketUtil.CreateNamePacket("logic")); init(); } catch (IOException e) { e.printStackTrace(); } }
void onRun(InputStream inputStream) throws IOException { int begin = 0; for (; ; ) { int end = inputStream.read(recvBuffer, begin, recvBuffer.length - begin); if (end <= 0) return; end += begin; begin = 0; for (; ; ) { if (end - begin < 2) break; int packetLen = PacketUtil.ReadShort(recvBuffer, begin); if (end - begin < packetLen) break; packetRecvQueue.put(copyOfRange(recvBuffer, begin, begin + packetLen)); begin += packetLen; } if (begin >= end) { begin = 0; } else if (begin <= 0) { begin = end; } else { arraycopy(recvBuffer, begin, recvBuffer, 0, end - begin); begin = end - begin; } } }