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

项目:libgdxcn    文件:NetJavaSocketImpl.java   
public NetJavaSocketImpl (Protocol protocol, String host, int port, SocketHints hints) {
    try {
        // create the socket
        socket = new java.net.Socket();
        applyHints(hints); // better to call BEFORE socket is connected!

        // and connect...
        InetSocketAddress address = new InetSocketAddress(host, port);
        if (hints != null) {
            socket.connect(address, hints.connectTimeout);
        } else {
            socket.connect(address);
        }
    } catch (Exception e) {
        throw new GdxRuntimeException("Error making a socket connection to " + host + ":" + port, e);
    }
}
项目:libgdxcn    文件:NetJavaSocketImpl.java   
private void applyHints (SocketHints hints) {
    if (hints != null) {
        try {
            socket.setPerformancePreferences(hints.performancePrefConnectionTime, hints.performancePrefLatency,
                hints.performancePrefBandwidth);
            socket.setTrafficClass(hints.trafficClass);
            socket.setTcpNoDelay(hints.tcpNoDelay);
            socket.setKeepAlive(hints.keepAlive);
            socket.setSendBufferSize(hints.sendBufferSize);
            socket.setReceiveBufferSize(hints.receiveBufferSize);
            socket.setSoLinger(hints.linger, hints.lingerDuration);
            socket.setSoTimeout(hints.socketTimeout);
        } catch (Exception e) {
            throw new GdxRuntimeException("Error setting socket hints.", e);
        }
    }
}
项目:Cardshifter    文件:CardshifterNonGWTClient.java   
public CardshifterNonGWTClient(CardshifterPlatform platform, String host, int port,
     CardshifterMessageHandler handler, LoginMessage loginMessage) {
    socket = Gdx.net.newClientSocket(Net.Protocol.TCP, host, port, new SocketHints());
    output = socket.getOutputStream();
    input = socket.getInputStream();
    transformer = new ByteTransformer(new GdxLogger(), new GdxReflection());
    this.handler = handler;
    try {
        output.write("{ \"command\": \"serial\", \"type\": \"1\" }".getBytes());
        output.flush();
        Gdx.app.log("Client", "Sent serial type");
        platform.setupLogging();
        send(loginMessage);
    } catch (IOException e) {
        e.printStackTrace();
        throw new RuntimeException(e);
    }
    new Thread(this).start();
}
项目:LibGDXServer    文件:ClientSocket.java   
public ClientSocket(Net.Protocol protocol, String host, int port, SocketHints hints) {
    try {
        // create the socket
        socket = new java.net.Socket();
        applyHints(hints);  // better to call BEFORE socket is connected!

        // and connect...
        InetSocketAddress address = new InetSocketAddress(host, port);
        if (hints != null) {
            socket.connect(address, hints.connectTimeout);
        } else {
            socket.connect(address);
        }
    } catch (Exception e) {
        throw new GdxRuntimeException("Error making a socket connection to " + host + ":" + port, e);
    }
}
项目:LibGDXServer    文件:ClientSocket.java   
private void applyHints(SocketHints hints) {
    if (hints != null) {
        try {
            socket.setPerformancePreferences(hints.performancePrefConnectionTime,
                    hints.performancePrefLatency,
                    hints.performancePrefBandwidth);
            socket.setTrafficClass(hints.trafficClass);
            socket.setTcpNoDelay(hints.tcpNoDelay);
            socket.setKeepAlive(hints.keepAlive);
            socket.setSendBufferSize(hints.sendBufferSize);
            socket.setReceiveBufferSize(hints.receiveBufferSize);
            socket.setSoLinger(hints.linger, hints.lingerDuration);
        } catch (Exception e) {
            throw new GdxRuntimeException("Error setting socket hints.", e);
        }
    }
}
项目:cachebox3.0    文件:FileBrowserClint.java   
public boolean connect() {

        if (socket != null) {
            if (socket.isConnected())
                return true;
        }

        try {
            SocketHints hints = new SocketHints();
            socket = Gdx.net.newClientSocket(Net.Protocol.TCP, serverAddress, serverPort, hints);

            os = socket.getOutputStream();
            bos = new BufferedOutputStream(os, BUFFER_SIZE);
            dos = new DataOutputStream(bos);
            in = socket.getInputStream();
            bis = new BufferedInputStream(in, BUFFER_SIZE);
            dis = new DataInputStream(bis);

            dos.writeUTF(CONNECT);
            dos.flush();

            String response = dis.readUTF();
            log.debug("got server message: " + response);

            if (response.equals(CONNECTED)) {
                return true;
            }
        } catch (Exception e) {
            log.error("an error occured", e);
        }
        return false;
    }
项目:dice-heroes    文件:LocalMultiplayer.java   
public void init() {
    if (initialized)
        return;
    invitesWindow = new InvitesWindow();
    playersWindow = new InvitesWindow();
    initialized = true;
    try {
        socket = Gdx.net.newClientSocket(Net.Protocol.TCP, "localhost", 1337, new SocketHints());
    } catch (Exception e) {
        return;
    }

    new Thread(new Runnable() {
        @Override public void run() {
            final BufferedReader r = new BufferedReader(new InputStreamReader(socket.getInputStream()));
            while (true) {
                try {
                    final String msg = r.readLine();
                    Gdx.app.postRunnable(new Runnable() {
                        @Override public void run() {
                            ClientServerMessage message = ClientServerMessage.json.fromJson(ClientServerMessage.class, msg);
                            receive(message);
                        }
                    });
                } catch (IOException ignored) {
                    System.out.println(ignored.getMessage());
                }
            }
        }
    }).start();
    sendToServer(ClientServerMessage.Type.loadPlayersToInvite);
    sendToServer(ClientServerMessage.Type.loadInvites);
}
项目:libgdxcn    文件:NetJavaServerSocketImpl.java   
@Override
public Socket accept (SocketHints hints) {
    try {
        return new NetJavaSocketImpl(server.accept(), hints);
    } catch (Exception e) {
        throw new GdxRuntimeException("Error accepting socket.", e);
    }
}
项目:LibGDXServer    文件:ServerApplicationSocket.java   
@Override
public Socket accept(SocketHints hints) {
    try {
        return new ClientSocket(server.accept(), hints);
    } catch (Exception e) {
        throw new GdxRuntimeException("Error accepting socket.", e);
    }
}
项目:JavityEngine    文件:JavityNet.java   
public Socket newClientSocket(Protocol protocol, String host, int port, SocketHints hints) {
    return nativeNet.newClientSocket(protocol, host, port, hints);
}
项目:gdx-backend-jglfw    文件:JglfwNet.java   
public Socket newClientSocket (Protocol protocol, String host, int port, SocketHints hints) {
    return new NetJavaSocketImpl(protocol, host, port, hints);
}
项目:gdx-lml    文件:ExtendedNet.java   
@Override
public Socket newClientSocket(final Protocol protocol, final String host, final int port, final SocketHints hints) {
    return net.newClientSocket(protocol, host, port, hints);
}
项目:libgdxcn    文件:NetJavaSocketImpl.java   
public NetJavaSocketImpl (java.net.Socket socket, SocketHints hints) {
    this.socket = socket;
    applyHints(hints);
}
项目:libgdxcn    文件:JglfwNet.java   
public Socket newClientSocket (Protocol protocol, String host, int port, SocketHints hints) {
    return new NetJavaSocketImpl(protocol, host, port, hints);
}
项目:libgdxcn    文件:GwtNet.java   
@Override
public Socket newClientSocket (Protocol protocol, String host, int port, SocketHints hints) {
    throw new UnsupportedOperationException("Not implemented");
}
项目: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);
}
项目:TinyVoxel    文件:GwtNet.java   
@Override
public Socket newClientSocket (Protocol protocol, String host, int port, SocketHints hints) {
    throw new UnsupportedOperationException("Not implemented");
}
项目:LibGDXServer    文件:ClientSocket.java   
public ClientSocket(java.net.Socket socket, SocketHints hints) {
    this.socket = socket;
    applyHints(hints);
}
项目:LibGDXServer    文件:ServerNet.java   
@Override
public Socket newClientSocket(Protocol protocol, String host, int port, SocketHints hints) {
    return new ClientSocket(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);
}
项目:libgdxcn    文件:Net.java   
/** Creates a new TCP client socket that connects to the given host and port.
 * 
 * @param host the host address
 * @param port the port
 * @param hints additional {@link SocketHints} used to create the socket. Input null to use the default setting provided by the
 *           system.
 * @return GdxRuntimeException in case the socket couldn't be opened */
public Socket newClientSocket (Protocol protocol, String host, int port, SocketHints hints);