public static class NioServer.Event
extends java.util.EventObject
NioServer
.
This code is released into the Public Domain. Since this is Public Domain, you don't need to worry about licensing, and you can simply copy this NioServer.java file to your own package and use it as you like. Enjoy. Please consider leaving the following statement here in this code:
This NioServer class was copied to this project from its source as found at iHarder.net.
NioServer
,
NioServer.Adapter
,
NioServer.Listener
,
Serialized FormConstructor and Description |
---|
Event(NioServer src)
Creates a Event based on the given
NioServer . |
Modifier and Type | Method and Description |
---|---|
java.nio.ByteBuffer |
getBuffer()
Returns the
ByteBuffer that contains
the data for this connection. |
java.nio.channels.SelectionKey |
getKey()
Returns the SelectionKey associated with this event.
|
java.net.SocketAddress |
getLocalSocketAddress()
Returns the local address/port to which this connection
is bound.
|
NioServer |
getNioServer()
Returns the source of the event, a
NioServer . |
java.net.SocketAddress |
getRemoteSocketAddress()
Returns the address of the endpoint this socket is
connected to, or null if it is unconnected.
|
NioServer.State |
getState()
Shorthand for getNioServer().getState().
|
boolean |
isTcp()
Convenience method for checking
getKey().channel() instanceof SocketChannel . |
boolean |
isUdp()
Convenience method for checking
getKey().channel() instanceof DatagramChannel . |
protected void |
reset(java.nio.channels.SelectionKey key,
java.nio.ByteBuffer buffer,
java.net.SocketAddress remoteUdp)
Resets an event between firings by updating the parameters
that change.
|
public NioServer getNioServer()
NioServer
.
Shorthand for (NioServer)getSource().public NioServer.State getState()
NioServer.State
public java.nio.channels.SelectionKey getKey()
protected void reset(java.nio.channels.SelectionKey key, java.nio.ByteBuffer buffer, java.net.SocketAddress remoteUdp)
key
- The SelectionKey for the eventbuffer
- remoteUdp
- the remote UDP source or null for TCPpublic java.nio.ByteBuffer getBuffer()
Returns the ByteBuffer
that contains
the data for this connection. Read from it as much as
you can. Any data that remains on or after the value
of position()
will be saved for the next
time an event is fired. In this way, you can defer
processing incomplete data until everything arrives.
Example: You are receiving lines of text. The ByteBuffer returned here contains one and a half lines of text. When you realize this, you process the first line as you like, but you leave this buffer's position at the beginning of the second line. In this way, The beginning of the second line will be the start of the buffer the next time around.
public java.net.SocketAddress getLocalSocketAddress()
Returns the local address/port to which this connection is bound. That is, if you are listening on port 80, then this might return something like an InetSocketAddress (probably) that indicated /127.0.0.1:80.
This is essentially a convenience method for returning the same-name methods from the key's channel after checking the type of channel (SocketChannel or DatagramChannel).
public java.net.SocketAddress getRemoteSocketAddress()
Returns the address of the endpoint this socket is connected to, or null if it is unconnected.
This is essentially a convenience method for returning the same-name methods from the key's channel after checking the type of channel (SocketChannel or DatagramChannel).
public boolean isTcp()
getKey().channel() instanceof SocketChannel
.public boolean isUdp()
getKey().channel() instanceof DatagramChannel
.