Package com.example.common.transport.tcp
Class TcpSocketTransportFactory
java.lang.Object
com.example.common.transport.tcp.TcpSocketTransportFactory
- All Implemented Interfaces:
TransportFactory
The TcpSocketTransportFactory class implements the TransportFactory interface for creating TCP socket
listeners and connections.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncreateConnection
(String ip, int port, String encoding) Create a TCP socket transport connection to the specified IP address and port with the given encoding.createListener
(int port, int maxCountConnections, String encoding) Create a TCP socket transport listener on the specified port with the given maximum count of connections and encoding.
-
Constructor Details
-
TcpSocketTransportFactory
public TcpSocketTransportFactory()
-
-
Method Details
-
createListener
public TransportListener createListener(int port, int maxCountConnections, String encoding) throws IOException Create a TCP socket transport listener on the specified port with the given maximum count of connections and encoding.- Specified by:
createListener
in interfaceTransportFactory
- Parameters:
port
- the port number to listen onmaxCountConnections
- the maximum number of connections allowedencoding
- the encoding used for communication- Returns:
- a TcpSocketTransportListener object
- Throws:
IOException
- if an error occurs during listener creation
-
createConnection
public TransportConnection createConnection(String ip, int port, String encoding) throws IOException Create a TCP socket transport connection to the specified IP address and port with the given encoding.- Specified by:
createConnection
in interfaceTransportFactory
- Parameters:
ip
- the IP address to connect toport
- the port number to connect toencoding
- the encoding used for communication- Returns:
- a TcpSocketTransportConnection object
- Throws:
IOException
- if an error occurs during connection creation
-