com.jme3.network.kernel.tcp
Class SocketConnector

java.lang.Object
  extended by com.jme3.network.kernel.tcp.SocketConnector
All Implemented Interfaces:
Connector

public class SocketConnector
extends java.lang.Object
implements Connector

A straight forward socket-based connector implementation that does not use any separate threading. It relies completely on the buffering in the OS network layer.


Constructor Summary
SocketConnector(java.net.InetAddress address, int port)
           
 
Method Summary
 boolean available()
          Returns true if there is currently data available for reading.
protected  void checkClosed()
           
 void close()
          Closes the connection.
 boolean isConnected()
          Returns true if this connector is currently connected.
 java.nio.ByteBuffer read()
          Reads a chunk of data from the connection, blocking if there is no data available.
 void write(java.nio.ByteBuffer data)
          Writes a chunk of data to the connection from data.position() to data.limit().
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SocketConnector

public SocketConnector(java.net.InetAddress address,
                       int port)
                throws java.io.IOException
Throws:
java.io.IOException
Method Detail

checkClosed

protected void checkClosed()

isConnected

public boolean isConnected()
Description copied from interface: Connector
Returns true if this connector is currently connected.

Specified by:
isConnected in interface Connector

close

public void close()
Description copied from interface: Connector
Closes the connection. Any subsequent attempts to read or write will fail with an exception.

Specified by:
close in interface Connector

available

public boolean available()
Description copied from interface: Connector
Returns true if there is currently data available for reading. Some connector implementations may not be able to answer this question accurately and will always return false.

Specified by:
available in interface Connector

read

public java.nio.ByteBuffer read()
Description copied from interface: Connector
Reads a chunk of data from the connection, blocking if there is no data available. The buffer may only be valid until the next read() call is made. Callers should copy the data if they need it for longer than that.

Specified by:
read in interface Connector
Returns:
The data read or null if there is no more data because the connection is closed.

write

public void write(java.nio.ByteBuffer data)
Description copied from interface: Connector
Writes a chunk of data to the connection from data.position() to data.limit().

Specified by:
write in interface Connector