Package com.tenio.network
Class Connection
- java.lang.Object
-
- com.tenio.network.Connection
-
- Direct Known Subclasses:
NettyConnection
public abstract class Connection extends java.lang.Object
A connection is created when the first request from client reach and pass in your server. The connection has some types based on its client's request type (TCP, UDP, WebSocket). It can work stand-alone for some cases by but most of the time, it is a part of a particular player. You can send a message from the server-side to one client via its corresponding connection/player. Once the connection is established, it should be attached to a player or be refused (be disconnected) as soon as possible.- Author:
- kong
-
-
Field Summary
Fields Modifier and Type Field Description protected IEventManager
_eventManager
static java.lang.String
KEY_STR_CONNECTION
-
Constructor Summary
Constructors Constructor Description Connection(IEventManager eventManager, ConnectionType type, int index)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract void
clean()
Delete the keys which are used to identify a player in one "connection".abstract void
close()
Close a "connection" between a client with the serverjava.lang.String
getAddress()
Retrieve the "connection" address in string typeint
getIndex()
abstract Connection
getThis()
Retrieve this connection itself by channelConnectionType
getType()
Retrieve the "connection" type, seeConnectionType
java.lang.String
getUsername()
Retrieve the "connection" id, this id is player's name, seeAbstractPlayer.getName()
boolean
isType(ConnectionType type)
Determine if the current type of connection is matched or not?abstract void
removeThis()
Remove the connection object from channel cachevoid
removeUsername()
Remove the username value from channel cacheabstract void
send(TObject message)
Send a message to the clientvoid
setAddress(java.lang.String address)
Set the addressabstract void
setRemote(java.net.InetSocketAddress remote)
Set the current address for your "connection" (only need for Socket type)abstract void
setThis()
Set this connection into current channel Note: Set value for one key.void
setUsername(java.lang.String username)
Set id for the "connection", this id is player's name, seeAbstractPlayer.getName()
-
-
-
Field Detail
-
KEY_STR_CONNECTION
public static final java.lang.String KEY_STR_CONNECTION
- See Also:
- Constant Field Values
-
_eventManager
protected final IEventManager _eventManager
-
-
Constructor Detail
-
Connection
public Connection(IEventManager eventManager, ConnectionType type, int index)
-
-
Method Detail
-
getType
public ConnectionType getType()
Retrieve the "connection" type, seeConnectionType
- Returns:
- the type of connection
-
isType
public boolean isType(ConnectionType type)
Determine if the current type of connection is matched or not?- Parameters:
type
- the comparison type- Returns:
- true is the current type is matched, false otherwise.
-
getIndex
public int getIndex()
- Returns:
- the current index of connection in one player
-
getUsername
public java.lang.String getUsername()
Retrieve the "connection" id, this id is player's name, seeAbstractPlayer.getName()
- Returns:
- the username
-
setUsername
public void setUsername(java.lang.String username)
Set id for the "connection", this id is player's name, seeAbstractPlayer.getName()
- Parameters:
username
- the identify of this connection
-
removeUsername
public void removeUsername()
Remove the username value from channel cache
-
setAddress
public void setAddress(java.lang.String address)
Set the address- Parameters:
address
- the new address value
-
getAddress
public java.lang.String getAddress()
Retrieve the "connection" address in string type- Returns:
- the address
-
send
public abstract void send(TObject message)
Send a message to the client- Parameters:
message
- the message content, seeTObject
-
close
public abstract void close()
Close a "connection" between a client with the server
-
clean
public abstract void clean()
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
-
setRemote
public abstract void setRemote(java.net.InetSocketAddress remote)
Set the current address for your "connection" (only need for Socket type)- Parameters:
remote
- , seeInetSocketAddress
-
getThis
public abstract Connection getThis()
Retrieve this connection itself by channel- Returns:
- the current connection
-
setThis
public abstract void setThis()
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)
-
removeThis
public abstract void removeThis()
Remove the connection object from channel cache
-
-