Samchon Framework for CPP
1.0.0
|
#include <ServerConnector.hpp>
Public Member Functions | |
ServerConnector (IProtocol *listener) | |
virtual | ~ServerConnector ()=default |
virtual void | connect (const std::string &ip, int port) |
Public Member Functions inherited from samchon::protocol::Communicator | |
virtual void | close () |
virtual void | replyData (std::shared_ptr< Invoke > invoke) |
virtual void | sendData (std::shared_ptr< Invoke > invoke) |
A server connector.
The ServerConnector class is a type of Communicator, specified for connecting to remote server who follows Samchon Framework's own protocol and taking full charge of network communication with the remote server.
Create a ServerConnector instance from a { listener} and call the connect() method. Then whenever a replied message comes from the remote system, the message will be converted to an Invoke object and the Invoke object will be shifted to the listener's IProtocol.replyData method. Below code is an example connecting to remote server and interacting with it.
Note that, ServerConnector connects to a remote server who follows the protocol of Samchon Framework's own. If the remote server is following web-socket protocol, then use WebServerConnector instead.
Protocol | Derived Type | Connect to |
---|---|---|
Samchon Framework's own | ServerConnector | Server |
Web-socket protocol | WebServerConnector | WebServer |
Definition at line 37 of file ServerConnector.hpp.
|
inline |
Construct from listener.
listener | A listener object to listen replied message from newly connected client in replyData() as an Invoke object. |
Definition at line 55 of file ServerConnector.hpp.
References ~ServerConnector().
|
virtualdefault |
|
inlinevirtual |
Connect to a server.
Connects to a server with specified host address and port number. After the connection has succeeded, callback function onConnect is called. Listening data from the connected server also begins. Replied messages from the connected server will be converted to Invoke classes and will be shifted to the listener's replyData() method.
If the connection fails immediately, either an event is dispatched or an exception is thrown: an error event is dispatched if a host was specified, and an exception is thrown if no host was specified. Otherwise, the status of the connection is reported by an event. If the socket is already connected, the existing connection is closed first.
ip | The name or IP address of the host to connect to. If no host is specified, the host that is contacted is the host where the calling file resides. If you do not specify a host, use an event listener to determine whether the connection was successful. |
port | The port number to connect to. |
Reimplemented in samchon::protocol::WebServerConnector.
Definition at line 87 of file ServerConnector.hpp.
Referenced by samchon::templates::parallel::MediatorClient::start().