Развитие детей ЭСТЕР
Облачный рендеринг. Быстро и удобно
☆ от 50 руб./час ☆ AnaRender.io
У вас – деньги. У нас – мощности. Считайте с нами!

SDOLS Software Iport documentation

IPORT Library v1.01

1. What is IPORT Library..
2. Global functions
 2.2 BeginService and FinishService
 2.3 OpenConnection and CloseConnection
3. How does IIpService work.
4. IIpService interface methods.
5. IIpConnection interface methods.
 5.1 Using IIpConnection with TRANS_TCP
  5.1.1  Sending data through connection
  5.1.2  Receiving data through connection
  5.1.3  Synchronous send and receive
 5.2 Using IIpConnection with TRANS_UDP
  5.2.1 Sending data through connection
 5.3 Using IIpConnection from callbacks
  5.3.1  Sending data through connection
  5.3.2  Retrieving received data package
  5.3.3  Retrieving other data
 5.4  Obtaining socket descriptor.
6. Some important definitions
7. Technical support
8. How to register.

1. What is IPORT Library.
        If you are willing to make a network application , for example FTP
server or WWW browser or multiplayer game or any other application which uses
Windows Sockets, you will find that you have to spend some time to organize
your network traffic in some way and to write some socket-code using Windows
Sockets. IPORT library makes all socket-programming for You, so You can
concentrate on more important things. You will see that IPORT is very simple. and is very easy to use.
IPORT contains two C++ interfaces and six global functions.
IIpConnection interface deals with single socket and have methods to
invoke/close connection and send/receive data. It is used both in client
and server applications. (details in Chapter 5.) IIpService is used to
create TCP/IP and UDP/IP services ( daemons ). It is invoked by global
fuctions. IIpService calls user defined callback functions when remote client
connects or disconnects and when data package arrives. ( details in Chapter 4)
        In the lower chapters i'll give help on all interfaces and their
        There are four sample projects included into archieve:
      * TCPSRV           // sample TCP/IP service
      * TCPCLIENT        // sample TCP/IP client application
      * UDPSRV           // sample UDP/IP service
      * UDPCLIENT        // sample UDP/IP client

I suggest you to look through samples to get more information about how to
use IPORT library.

2.  Global functions.
        There are six global functions exported by IPORT.DLL:
* BeginService
* FinishService
* OpenConnection
* CloseConnection

     IP_OPEN must be called once per application in the very beginning,
before any other IPORT function is called. It initializes the network engine.
     IP_CLOSE must be called when application is finishing its work. No IPORT
function will work correctly after IP_CLOSE call.

void main ()
 IP_OPEN ();

2.2  BeginService and FinishService
int BeginService ( const TRANSPORT_TYPE type, int port,
                   TRANSPORTER_CALLBACK_TYPE  lpCallBack,
                   TRANSPORTER_CALLBACK_TYPE  lpAcceptCallBack,
                   TRANSPORTER_CALLBACK_TYPE lpDisconnectCallBack,
                   IIpHost** IDaemon).

[in] type :                 can be TRANS_TCP or TRANS_UDP
[in] port :                 any legal IP port number
[in] lpCallBack:            user callback function. Is called when data
[in] lpAcceptCallBack:      user callback function. Is called when new
                            connection is accepted.
[in] lpDisconnectCallBack:  user callback function. Is called when
                            connection is closed due to network error.
[out]  IDaemon:             pointer to an IIpService.

Return values:
NULL if success.
-1 if IP_OPEN was not called before or if port is in use by other
Parameters lpAcceptCallBack and lpDisconnectCallBack are ignored if
parameter type is TRANS_UDP.

void FinishDaemon( IIpService* IDaemon )
[in] IDaemon    : pointer to a service to be finished.
This function sends a signal to a daemon object and then waits
for it to close it's threads. This procedure usually takes some time.
See example application to know more of BeginService and FinishService.

2.1  OpenConnection and CloseConnection.
int OpenConnection(     const char* host,
const int port,
const TRANSPORT_TYPE type,
IIpConnection** IConnection )
[in] host                        zterminated string. ip address ( ex.: "localhost")
[in] port                        any legal port number
[in] type                        Can be TRANS_TCP or TRANS_UDP
[in] lpMsgCallBack               Message callback for asynchronous connection
[in] lpDisconnectCallBack        Disconnect callback for asynchronous connection
[out] IConnection                pointer to IIpConnection

Return values:
NULL is success
-1 - for TRANS_TCP - connection is not established.
     for TRANS_UDP - can not resolve ip address.
If parameter type is TRANS_UDP callback parameters are ignored.
If lpMsgCallBack is nonzero and type is TRANS_TCP connection borns
a specific thread to process input from the connection. When data package
arrives this thread calls user callback function. See TCPCLIENT sample
to get more information about this mechanism.

void CloseConnection ( IIpConnection* IConnection )
[in] IConnection        - pointer to connection to be closed.
You can use CloseConnection only with connections previously opened
with OpenConnection.

3.  How does IIpService work.
        IIpService stores all connections in queue. You can access this
queue using IIpService::GetConnectionList() method. After connection is
closed by any reason, IIpService deletes it from the queue.
       IIpService creates two threads. First is called 'Listen Thread' and
is responsible for accepting connections and reading data from sockets. Other
one is called 'Message Processing Thread' and it is used to process received
data packages.
     This multithread model is used to provide better perfomance. One
important thing you should know about callbacks. AcceptCallBack and
DisconnectCallBack are called from Listen Thread. So do not put any heavy
algorythms there. It must not take much time to execute these callback
functions. Message callback is called from Message Processing Thread. So
Listen Thread can read some data package while your program is analysing
another data package.

4. IIpService interface methods
bool Alive ()
Return values:
Returns 'true' if daemon' threads are working.
if ( !myhost->Alive() )
    fprintf( stderr, "error: daemon already finished"

IIpConnection* GetConnectionList()
Returns value:
Returns a pointer to the IIpConnection queue or NULL if queue is empty.
Can be used ONLY for TRANS_TCP connection type.
GetConnectionList() is used to access connections from outside callback
void SendToAll ( IIpHost* myhost, char* buffer, int bufflen )
IIpConnection *i,*ConnQueue = myhost->GetConnectionList();

for ( i = ConnQueue ; i; i = i->GetNext() )
        i->SendPKT ( lpstrBuffer, nBufferLen );

int CloseConnection ( int ID )
Closes connection with the given identifier.
Return values:
Returns NULL if success and non-zero if ID is not found in the queue.
Can be used ONLY for TRANS_TCP connection type.
int SlayFirstConnectionFromQueue ( IIpHost* myhost )
IIpConnection *conn = myhost->GetConnectionList();
if ( !conn )
// Queue is empty.
return -1;
id = conn->GetID();
myhost->CloseConnection( id );
return id;

5.  IIpConnection interface methods
5.1  Using IIpConnection with TRANS_TCP
5.1.1  Sending data through connection
 int SendPKT ( const char* pkt, int size )
 [in] pkt  :            pointer to a buffer to be sent
 [in] size :            size of the buffer
 Return values:
 Returns ammount of bytes really sent or error

5.1.2  Receiving data through connection
 int RecvPKT ( char* pkt, int& size, timeval* timeout)
 Receives a data package.
 [out] pkt   :  pointer to a buffer to store received data
 [out] size  :  size of received data package
 [in] timeout:  time to wait for package.
 Return values:
 Returns NULL if success and -1 if no data is received
 during the timeout.

5.1.3  Synchronous send and receive
 int SendSynchPKT( const char* in_pkt, int in_size,
          char* out_pkt, int& out_size,
         timeval* timeout )
 Sends a data package and waits for answer.
 See SendPKT and RecvPKT
 Return values:
 Returns NULL if success and -1 if no answer was received
 during the timeout.

5.2  Using IIpConnection with TRANS_UDP
 5.2.1 Sending data through connection
 voidSendDatagram( char*pkt, int size )
 Sends data package. Similar to SendPKT but uses UDP instead of TCP.

5.3  Using IIpConnection from CallBacks
5.3.1  Sending data through connection
 When using TRANS_TCP you can IIpConnection::SendPKT to send data to the
given connection.
5.3.2  Retrieving received data package

 char* GetData ()
 Return value:
 returns pointer to the received data package or NULL if no data was received.

 int GetDataSize ()
 Return value:
 returns size of the received data package or NULL if no data was received.

5.3.3  Retrieving other data
 int GetID ()
 Return value:
 Returns the unique connection identifier.

5.4  Obtaining socket descriptor.
 Sometime it can be nessesary to obtain socket descriptor. ( for example
to perform some WinSock procedures ( such as setsockopt ) with them.

 sock_t GetDescriptor ()
 Return value:
 Returns a socket associated with give IIpConnection.

6. Some important definitions

MAX_SESSIONS            Defines the maximal ammount of active
connections served by IIpService at once.
HOST_LENGTH             Maximal length of the host name in bytes.

7.  Technical support.
If You are having problems using IPORT library - feel free to ask me.
My e-mail is sdols@mail.ru and i would try to answer all questions.
For now my site is under construction but soon it would work at

8.  IPORT Library is a Shareware product. This mean that you have to get
a registered version of the IPORT Library if you want to use it in your
commercial products.


You can purchase IPORT Library v1.01 at the following sites: