Java 类com.badlogic.gdx.net.NetJavaSocketImpl 实例源码

项目:Cubes_2    文件:ClientConnectionInitializer.java   
public static Socket extractJavaSocket(com.badlogic.gdx.net.Socket gdxSocket) throws IOException {
    if (gdxSocket instanceof NetJavaSocketImpl) {
        try {
            Field f = NetJavaSocketImpl.class.getDeclaredField("socket");

            Socket javaSocket = (java.net.Socket) f.get(gdxSocket);
            if (javaSocket != null) {
                return javaSocket;
            } else {
                  throw new Error();;
            }
        } catch (Exception e) {
            throw new IOException("Failed to get java socket", e);
        }
    } else {
        throw new IOException("libGDX socket is not a " + NetJavaSocketImpl.class.getSimpleName());
    }
}
项目:Cubes_2    文件:ServerConnectionInitializer.java   
private static void initialConnect(Socket javaSocket, NetJavaSocketImpl gdxSocket) throws Exception {
  javaSocket.setSoTimeout(TIMEOUT);
  DataInputStream dataInputStream = new DataInputStream(javaSocket.getInputStream());
  byte b = dataInputStream.readByte();
  DataOutputStream dataOutputStream = new DataOutputStream(javaSocket.getOutputStream());
  dataOutputStream.writeInt(Branding.VERSION_MAJOR);
  dataOutputStream.writeInt(Branding.VERSION_MINOR);
  dataOutputStream.writeInt(Branding.VERSION_POINT);
  dataOutputStream.writeInt(Branding.VERSION_BUILD);
  dataOutputStream.writeUTF(Branding.VERSION_HASH);
  switch (b) {
    case 0:
      connect(javaSocket, gdxSocket, dataOutputStream, dataInputStream);
      return;
    case 1:
      ping(javaSocket, gdxSocket, dataOutputStream, dataInputStream);
      return;
    default:
      throw new IOException("Unrecognised connection code " + b);
  }
}
项目:Cubes    文件:ClientConnectionInitializer.java   
public static Socket extractJavaSocket(com.badlogic.gdx.net.Socket gdxSocket) throws IOException {
  if (gdxSocket instanceof NetJavaSocketImpl) {
    try {
      Field f = NetJavaSocketImpl.class.getDeclaredField("socket");
      f.setAccessible(true);
      Socket javaSocket = (java.net.Socket) f.get(gdxSocket);
      if (javaSocket != null) {
        return javaSocket;
      } else {
        throw new NullPointerException();
      }
    } catch (Exception e) {
      throw new IOException("Failed to get java socket", e);
    }
  } else {
    throw new IOException("libGDX socket is not a " + NetJavaSocketImpl.class.getSimpleName());
  }
}
项目:Cubes    文件:ServerConnectionInitializer.java   
private static void initialConnect(Socket javaSocket, NetJavaSocketImpl gdxSocket) throws Exception {
  javaSocket.setSoTimeout(TIMEOUT);
  DataInputStream dataInputStream = new DataInputStream(javaSocket.getInputStream());
  byte b = dataInputStream.readByte();
  DataOutputStream dataOutputStream = new DataOutputStream(javaSocket.getOutputStream());
  dataOutputStream.writeInt(Branding.VERSION_MAJOR);
  dataOutputStream.writeInt(Branding.VERSION_MINOR);
  dataOutputStream.writeInt(Branding.VERSION_POINT);
  dataOutputStream.writeInt(Branding.VERSION_BUILD);
  dataOutputStream.writeUTF(Branding.VERSION_HASH);
  switch (b) {
    case 0:
      connect(javaSocket, gdxSocket, dataOutputStream, dataInputStream);
      return;
    case 1:
      ping(javaSocket, gdxSocket, dataOutputStream, dataInputStream);
      return;
    default:
      throw new IOException("Unrecognised connection code " + b);
  }
}
项目:Cubes_2    文件:ServerConnectionInitializer.java   
private static void ping(Socket javaSocket, NetJavaSocketImpl gdxSocket, DataOutputStream dataOutputStream, DataInputStream dataInputStream) throws Exception {
  Log.debug(gdxSocket.getRemoteAddress() + " pinged the server");
  List<ClientIdentifier> clients = Cubes.getServer().getAllClients();
  dataOutputStream.writeInt(clients.size());
  for (ClientIdentifier client : clients) {
    dataOutputStream.writeUTF(client.getPlayer().username);
  }
  dataOutputStream.flush();
  gdxSocket.dispose();
}
项目:Cubes    文件:ServerConnectionInitializer.java   
private static void ping(Socket javaSocket, NetJavaSocketImpl gdxSocket, DataOutputStream dataOutputStream, DataInputStream dataInputStream) throws Exception {
  Log.debug(gdxSocket.getRemoteAddress() + " pinged the server");
  List<ClientIdentifier> clients = Cubes.getServer().getAllClients();
  dataOutputStream.writeInt(clients.size());
  for (ClientIdentifier client : clients) {
    dataOutputStream.writeUTF(client.getPlayer().username);
  }
  dataOutputStream.flush();
  gdxSocket.dispose();
}
项目:Cubes_2    文件:ServerConnectionInitializer.java   
private Checker(Socket javaSocket, NetJavaSocketImpl gdxSocket) {
  this.javaSocket = javaSocket;
  this.gdxSocket = gdxSocket;
}
项目:Cubes_2    文件:ServerConnectionInitializer.java   
public static void check(com.badlogic.gdx.net.Socket gdxSocket) throws Exception {
  Socket javaSocket = extractJavaSocket(gdxSocket);
  NetJavaSocketImpl netJavaSocketImpl = (NetJavaSocketImpl) gdxSocket;
  Executor.execute(new Checker(javaSocket, netJavaSocketImpl));
}
项目:Cubes_2    文件:ServerConnectionInitializer.java   
private static void connect(Socket javaSocket, NetJavaSocketImpl gdxSocket, DataOutputStream dataOutputStream, DataInputStream dataInputStream) throws Exception {
  javaSocket.setSoTimeout(0);
  ((ServerNetworking) Side.getNetworking()).accepted(gdxSocket);
}
项目:Cubes    文件:ServerConnectionInitializer.java   
private Checker(Socket javaSocket, NetJavaSocketImpl gdxSocket) {
  this.javaSocket = javaSocket;
  this.gdxSocket = gdxSocket;
}
项目:Cubes    文件:ServerConnectionInitializer.java   
public static void check(com.badlogic.gdx.net.Socket gdxSocket) throws Exception {
  Socket javaSocket = extractJavaSocket(gdxSocket);
  NetJavaSocketImpl netJavaSocketImpl = (NetJavaSocketImpl) gdxSocket;
  Executor.execute(new Checker(javaSocket, netJavaSocketImpl));
}
项目:Cubes    文件:ServerConnectionInitializer.java   
private static void connect(Socket javaSocket, NetJavaSocketImpl gdxSocket, DataOutputStream dataOutputStream, DataInputStream dataInputStream) throws Exception {
  javaSocket.setSoTimeout(0);
  ((ServerNetworking) Side.getNetworking()).accepted(gdxSocket);
}
项目:gdx-backend-jglfw    文件:JglfwNet.java   
public Socket newClientSocket (Protocol protocol, String host, int port, SocketHints hints) {
    return new NetJavaSocketImpl(protocol, host, port, hints);
}
项目:libgdxcn    文件:JglfwNet.java   
public Socket newClientSocket (Protocol protocol, String host, int port, SocketHints hints) {
    return new NetJavaSocketImpl(protocol, host, port, hints);
}
项目:libgdxcn    文件:HeadlessNet.java   
@Override
public Socket newClientSocket (Protocol protocol, String host, int port, SocketHints hints) {
    return new NetJavaSocketImpl(protocol, host, port, hints);
}
项目:libgdxcn    文件:IOSNet.java   
@Override
public Socket newClientSocket (Protocol protocol, String host, int port, SocketHints hints) {
    return new NetJavaSocketImpl(protocol, host, port, hints);
}
项目:libgdxcn    文件:LwjglNet.java   
@Override
public Socket newClientSocket (Protocol protocol, String host, int port, SocketHints hints) {
    return new NetJavaSocketImpl(protocol, host, port, hints);
}
项目:libgdxcn    文件:AndroidNet.java   
@Override
public Socket newClientSocket (Protocol protocol, String host, int port, SocketHints hints) {
    return new NetJavaSocketImpl(protocol, host, port, hints);
}
项目:mini2Dx    文件:IOSMini2DxNet.java   
@Override
public Socket newClientSocket (Protocol protocol, String host, int port, SocketHints hints) {
    return new NetJavaSocketImpl(protocol, host, port, hints);
}