Package com.tenio.network.netty
Class NettyConnection
- java.lang.Object
-
- com.tenio.network.Connection
-
- com.tenio.network.netty.NettyConnection
-
public class NettyConnection extends Connection
Use Netty to create a connection instance @seeConnection
- Author:
- kong
-
-
Field Summary
Fields Modifier and Type Field Description protected java.net.InetSocketAddress
__remote
Save the client's address, in Datagram connection it is used for saving as a key of theConnection.getUsername()
static io.netty.util.AttributeKey<Connection>
KEY_CONNECTION
Save this connection itself to its channel.-
Fields inherited from class com.tenio.network.Connection
_eventManager, KEY_STR_CONNECTION
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clean()
Delete the keys which are used to identify a player in one "connection".void
close()
Close a "connection" between a client with the serverConnection
getThis()
Retrieve this connection itself by channelstatic NettyConnection
newInstance(int index, IEventManager eventManager, ConnectionType type, io.netty.channel.Channel channel)
void
removeThis()
Remove the connection object from channel cachevoid
send(TObject message)
Send a message to the clientvoid
setRemote(java.net.InetSocketAddress remote)
Set the current address for your "connection" (only need for Socket type)void
setThis()
Set this connection into current channel Note: Set value for one key.-
Methods inherited from class com.tenio.network.Connection
getAddress, getIndex, getType, getUsername, isType, removeUsername, setAddress, setUsername
-
-
-
-
Field Detail
-
KEY_CONNECTION
public static final io.netty.util.AttributeKey<Connection> KEY_CONNECTION
Save this connection itself to its channel. In case of Datagram channel, we useConnection.__address
as a key for the current connection
-
__remote
protected java.net.InetSocketAddress __remote
Save the client's address, in Datagram connection it is used for saving as a key of theConnection.getUsername()
-
-
Method Detail
-
newInstance
public static NettyConnection newInstance(int index, IEventManager eventManager, ConnectionType type, io.netty.channel.Channel channel)
-
send
public void send(TObject message)
Description copied from class:Connection
Send a message to the client- Specified by:
send
in classConnection
- Parameters:
message
- the message content, seeTObject
-
close
public void close()
Description copied from class:Connection
Close a "connection" between a client with the server- Specified by:
close
in classConnection
-
getThis
public Connection getThis()
Description copied from class:Connection
Retrieve this connection itself by channel- Specified by:
getThis
in classConnection
- Returns:
- the current connection
-
setThis
public void setThis()
Description copied from class:Connection
Set this connection into current channel Note: Set value for one key. You can set your custom data to one connection to quick access. These keys and values should be saved to channel (which is defined by NIO mechanism)- Specified by:
setThis
in classConnection
-
removeThis
public void removeThis()
Description copied from class:Connection
Remove the connection object from channel cache- Specified by:
removeThis
in classConnection
-
setRemote
public void setRemote(java.net.InetSocketAddress remote)
Description copied from class:Connection
Set the current address for your "connection" (only need for Socket type)- Specified by:
setRemote
in classConnection
- Parameters:
remote
- , seeInetSocketAddress
-
clean
public void clean()
Description copied from class:Connection
Delete the keys which are used to identify a player in one "connection". This method need to be implemented when the "connection" type is Socket or WebSocket- Specified by:
clean
in classConnection
-
-