public Connector createConnector( int channel, int port ) throws IOException { return new SocketConnector( remoteAddress, port ); } }
public ByteBuffer read() { checkClosed(); try { // Read what we can int count = in.read(buffer); if( count < 0 ) { // Socket is closed close(); return null; } // Wrap it in a ByteBuffer for the caller return ByteBuffer.wrap( buffer, 0, count ); } catch( IOException e ) { if( !connected.get() ) { // Nothing to see here... just move along return null; } throw new ConnectorException( "Error reading from connection to:" + remoteAddress, e ); } }
public void write( ByteBuffer data ) { checkClosed(); try { out.write(data.array(), data.position(), data.remaining()); } catch( IOException e ) { throw new ConnectorException( "Error writing to connection:" + remoteAddress, e ); } }
public void close() { checkClosed(); try { Socket temp = sock; sock = null; connected.set(false); temp.close(); } catch( IOException e ) { throw new ConnectorException( "Error closing socket for:" + remoteAddress, e ); } }
public ByteBuffer read() { checkClosed(); try { // Read what we can int count = in.read(buffer); if( count < 0 ) { // Socket is closed close(); return null; } // Wrap it in a ByteBuffer for the caller return ByteBuffer.wrap( buffer, 0, count ); } catch( IOException e ) { if( !connected.get() ) { // Nothing to see here... just move along return null; } throw new ConnectorException( "Error reading from connection to:" + remoteAddress, e ); } }
public boolean available() { checkClosed(); try { return in.available() > 0; } catch( IOException e ) { throw new ConnectorException( "Error retrieving data availability for:" + remoteAddress, e ); } }
public void connectToServer( InetAddress address, int port, int remoteUdpPort ) throws IOException { UdpConnector fast = new UdpConnector( address, remoteUdpPort ); SocketConnector reliable = new SocketConnector( address, port ); setPrimaryConnectors( reliable, fast, new TcpConnectorFactory(address) ); } }
public ByteBuffer read() { checkClosed(); try { // Read what we can int count = in.read(buffer); if( count < 0 ) { // Socket is closed close(); return null; } // Wrap it in a ByteBuffer for the caller return ByteBuffer.wrap( buffer, 0, count ); } catch( IOException e ) { if( !connected.get() ) { // Nothing to see here... just move along return null; } throw new ConnectorException( "Error reading from connection to:" + remoteAddress, e ); } }
public boolean available() { checkClosed(); try { return in.available() > 0; } catch( IOException e ) { throw new ConnectorException( "Error retrieving data availability for:" + remoteAddress, e ); } }
/** * Creates a Client that communicates with the specified host and and separate TCP and UDP ports * using both reliable and fast transports. * * @param gameName This is the name that identifies the game. This must match * the target server's name or this client will be turned away. * @param version This is a game-specific verison that helps detect when out-of-date * clients have connected to an incompatible server. This must match * the server's version of this client will be turned away. * @param hostPort The remote TCP port on the server to which this client should * send reliable messages. * @param remoteUdpPort The remote UDP port on the server to which this client should * send 'fast'/unreliable messages. Set to -1 if 'fast' traffic should * go over TCP. This will completely disable UDP traffic for this * client. */ public static Client connectToServer( String gameName, int version, String host, int hostPort, int remoteUdpPort ) throws IOException { InetAddress remoteAddress = InetAddress.getByName(host); UdpConnector fast = remoteUdpPort == -1 ? null : new UdpConnector( remoteAddress, remoteUdpPort ); SocketConnector reliable = new SocketConnector( remoteAddress, hostPort ); return new DefaultClient( gameName, version, reliable, fast, new TcpConnectorFactory(remoteAddress) ); }
public void close() { checkClosed(); try { Socket temp = sock; sock = null; connected.set(false); temp.close(); } catch( IOException e ) { throw new ConnectorException( "Error closing socket for:" + remoteAddress, e ); } }
public Connector createConnector( int channel, int port ) throws IOException { return new SocketConnector( remoteAddress, port ); } }
public void close() { checkClosed(); try { Socket temp = sock; sock = null; connected.set(false); temp.close(); } catch( IOException e ) { throw new ConnectorException( "Error closing socket for:" + remoteAddress, e ); } }
public void connectToServer( InetAddress address, int port, int remoteUdpPort ) throws IOException { UdpConnector fast = new UdpConnector( address, remoteUdpPort ); SocketConnector reliable = new SocketConnector( address, port ); setConnectors( reliable, fast ); } }
public void write( ByteBuffer data ) { checkClosed(); try { out.write(data.array(), data.position(), data.remaining()); } catch( IOException e ) { throw new ConnectorException( "Error writing to connection:" + remoteAddress, e ); } }
/** * Creates a Client that communicates with the specified host and and separate TCP and UDP ports * using both reliable and fast transports. * * @param gameName This is the name that identifies the game. This must match * the target server's name or this client will be turned away. * @param version This is a game-specific verison that helps detect when out-of-date * clients have connected to an incompatible server. This must match * the server's version of this client will be turned away. * @param tcpPort The remote TCP port on the server to which this client should * send reliable messages. * @param udpPort The remote UDP port on the server to which this client should * send 'fast'/unreliable messages. Set to -1 if 'fast' traffic should * go over TCP. This will completely disable UDP traffic for this * client. */ public static Client connectToServer( String gameName, int version, String host, int hostPort, int remoteUdpPort ) throws IOException { InetAddress remoteAddress = InetAddress.getByName(host); UdpConnector fast = remoteUdpPort == -1 ? null : new UdpConnector( remoteAddress, remoteUdpPort ); SocketConnector reliable = new SocketConnector( remoteAddress, hostPort ); return new DefaultClient( gameName, version, reliable, fast ); }
public boolean available() { checkClosed(); try { return in.available() > 0; } catch( IOException e ) { throw new ConnectorException( "Error retrieving data availability for:" + remoteAddress, e ); } }
public void connectToServer( InetAddress address, int port, int remoteUdpPort ) throws IOException { UdpConnector fast = new UdpConnector( address, remoteUdpPort ); SocketConnector reliable = new SocketConnector( address, port ); setPrimaryConnectors( reliable, fast, new TcpConnectorFactory(address) ); } }
public void write( ByteBuffer data ) { checkClosed(); try { out.write(data.array(), data.position(), data.remaining()); } catch( IOException e ) { throw new ConnectorException( "Error writing to connection:" + remoteAddress, e ); } }
/** * Creates a Client that communicates with the specified host and and separate TCP and UDP ports * using both reliable and fast transports. * * @param gameName This is the name that identifies the game. This must match * the target server's name or this client will be turned away. * @param version This is a game-specific verison that helps detect when out-of-date * clients have connected to an incompatible server. This must match * the server's version of this client will be turned away. * @param hostPort The remote TCP port on the server to which this client should * send reliable messages. * @param remoteUdpPort The remote UDP port on the server to which this client should * send 'fast'/unreliable messages. Set to -1 if 'fast' traffic should * go over TCP. This will completely disable UDP traffic for this * client. */ public static Client connectToServer( String gameName, int version, String host, int hostPort, int remoteUdpPort ) throws IOException { InetAddress remoteAddress = InetAddress.getByName(host); UdpConnector fast = remoteUdpPort == -1 ? null : new UdpConnector( remoteAddress, remoteUdpPort ); SocketConnector reliable = new SocketConnector( remoteAddress, hostPort ); return new DefaultClient( gameName, version, reliable, fast, new TcpConnectorFactory(remoteAddress) ); }