Samchon Framework for CPP  1.0.0
samchon::protocol::ServerConnector Class Reference

#include <ServerConnector.hpp>

Collaboration diagram for samchon::protocol::ServerConnector:

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)
 

Detailed Description

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
Basic Components
See also
Server, IProtocol Protocol - Basic Components
Author
Jeongho Nam http://samchon.org

Definition at line 37 of file ServerConnector.hpp.

Constructor & Destructor Documentation

samchon::protocol::ServerConnector::ServerConnector ( IProtocol listener)
inline

Construct from listener.

Parameters
listenerA 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().

Here is the call graph for this function:

virtual samchon::protocol::ServerConnector::~ServerConnector ( )
virtualdefault

Default Destructor.

Referenced by ServerConnector().

Here is the caller graph for this function:

Member Function Documentation

virtual void samchon::protocol::ServerConnector::connect ( const std::string &  ip,
int  port 
)
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.

Parameters
ipThe 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.
portThe 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().

Here is the caller graph for this function:


The documentation for this class was generated from the following file: