FemtoScan Online SDK Documentation

Home :: FsOnlineSDK :: fsio classes

class SPMsocket

? ^ 
Bidirectional TCP/IP socket-based stream for message exchange between remote clients.

This stream is closely integrated with MessageType class.

Source:
../fsio/SPMSocket.h:42
Author:
ATC
Version:
1.0

Contents

^ 
EntityTypeScopeShort Description
~SPMsocketdestructor public Standart destructor.
SPMsocketconstructor public Default constructor
SPMsocketconstructor public Attach to the existing windows socket.
SPMsocketconstructor public Copy constructor.
Acceptmethod public Accept incoming connection.
Attachmethod public Attach to existing windows socket.
Cipherenum public Enumerates possible cipher types.
CipherModeenum public Enumerates possible cipher modes.
CipherPaddingenum public Enumerates possible cipher modes.
Closemethod public Close socket.
Connectmethod public Try to connect to the specified adddress.
DecryptSessionKeysstatic method publicundocumented
Detachmethod public Detach underlying windows socket
Digestenum public Enumerates possible digest types.
Disconnectmethod public Gracefully disconnect socket.
EncryptSessionKeysstatic method publicundocumented
FlushWriteBuffermethod public Try to send pending data.
FreeLinestatic method public Free buffer returned by ReadLine function.
GenerateSessionKeysstatic method publicundocumented
getCipherBlockSizestatic method public Get cipher block size.
getCipherKeyLengthstatic method public Get cipher key length.
GetClientAddrmethod public Get human-readable address of connected client.
getDigestKeyLengthstatic method public Get digest key length.
GetSessionIdleTimemethod public Get connect timeout
GetStatemethod public Get socket state.
GetWriteBufferSizemethod public Get write buffer size.
IsOkmethod public Check socket state.
isSecuredmethod public Get security state.
Listenmethod public Listen for incoming connections.
operator SOCKEToperator public Get underlying windows socket.
PutBackmethod public Rewind read buffer.
Readmethod public Read data from sream.
ReadLinemethod public Read next line from stream.
ReadMsgmethod public Read message from stream.
SecureDirectionenum public Enumerates possible secure modes.
setSecuritymethod public Configure security on socket.
SetSessionIdleTimemethod public Set connect timeout.
Stateenum public Enumerates possible socket states.
Writemethod public Write data to stream.
WriteLinemethod public Write line to stream.
WriteMsgmethod public Write message to stream.

destructor ~SPMsocket

? ^  > 
Standart destructor.
Source:
../fsio/SPMSocket.h:66
Code:
public virtual ~ SPMsocket ( )

constructor SPMsocket

? ^  < > 
Default constructor
Source:
../fsio/SPMSocket.h:48
Code:
public SPMsocket ( )

constructor SPMsocket

? ^  < > 
Attach to the existing windows socket.

This constructor should be used to create stream, attached to the windows socket, returned by call to the Accept .

Source:
../fsio/SPMSocket.h:56
Param:
sock windows socket attach to.
Code:
public SPMsocket ( SOCKET sock )

constructor SPMsocket

? ^  < > 
Copy constructor.
Source:
../fsio/SPMSocket.h:61
Code:
public SPMsocket ( const SPMsocket & sock )

method Accept

? ^  < > 
Accept incoming connection.

If socket is in listening state (IOListen), incomig connections (if any) can be accepted. The socket itself remains in listening state, but returned socket can be attached by SPMsocket and used for data transfer.

Source:
../fsio/SPMSocket.h:116
Returns:
accepted socket (if any). Otherwise returns INVALID_SOCKET value.
See Also:
SPMsocket, State, Attach
Code:
public SOCKET Accept ( )

method Attach

? ^  < > 
Attach to existing windows socket.
Source:
../fsio/SPMSocket.h:133
Param:
sock windows socket (e.g. returned by @link #Accept @endlink)
Returns:
true if attached successfully (all it needs is juast a valid sock value.
See Also:
Accept
Code:
public bool Attach ( SOCKET sock )

enum Cipher

? ^  < > 
Enumerates possible cipher types.

Source:
../fsio/SPMSocket.h:355
Code:
public enum Cipher { ciphNone ,
ciphDES ,
ciphTDES ,
ciphRijndael128 ,
ciphRijndael192 ,
ciphRijndael256 ,
ciphBlowFish ,
ciphTwoFish ,
}

enum CipherMode

? ^  < > 
Enumerates possible cipher modes.

Source:
../fsio/SPMSocket.h:374
Code:
public enum CipherMode { cmECB ,
cmCBC ,
cmCFB ,
}

enum CipherPadding

? ^  < > 
Enumerates possible cipher modes.

Source:
../fsio/SPMSocket.h:387
Code:
public enum CipherPadding { cpZeros ,
cpPKCS7 ,
}

method Close

? ^  < > 
Close socket.

First tryes to disconnect socket, then destroys it unconditionally. Frees all stream buffers. Socket state after this operation will be set to IOError.

Source:
../fsio/SPMSocket.h:74
See Also:
State
Code:
public bool Close ( )

method Connect

? ^  < > 
Try to connect to the specified adddress.

Since this routine can take significant amount of time, it is made user-cancellable. While tryyng to connect, the socket state will be IOConnect.

Source:
../fsio/SPMSocket.h:90
Params:
server server address in form "<address>:<port>", where <address> is DNS name or IPV4 address, <port> is TCP/IP port in decimal form, e.g. "www.nanoscopy.org:25000".
pccfn user-specified routine, function of type FSIOCancelConnectRoutine . If pccfn is set to NULL, the Connect routine will be performed in non-cancellable manner.
pParam user parameter to be transferred to FSIOCancelConnectRoutine.
Returns:
true if socket was connected.
See Also:
State
Code:
public bool Connect ( const char * server ,
FSIOCancelConnectRoutine pccfn = 0 ,
void * pParam = 0 )

static method DecryptSessionKeys

? ^  < > 
undocumented
Source:
../fsio/SPMSocket.h:463
Code:
public static bool DecryptSessionKeys ( const unsigned char * key ,
unsigned keylen ,
Digest digest ,
Cipher cipher ,
int cipher_key_length ,
const unsigned char * enckeydata ,
int enckeydatasize ,
unsigned * cipher_key_offset ,
unsigned char * keydata ,
unsigned * keydatasize )

method Detach

? ^  < > 
Detach underlying windows socket
Source:
../fsio/SPMSocket.h:138
Code:
public void Detach ( )

enum Digest

? ^  < > 
Enumerates possible digest types.

Source:
../fsio/SPMSocket.h:333
Code:
public enum Digest { digNone ,
digMD5 ,
digSHA1 ,
digSHA256 ,
digSHA384 ,
digSHA512 ,
}

method Disconnect

? ^  < > 
Gracefully disconnect socket.

Flush all pending write operations, shutdown write end, receive all remaining data, then put socket in disconnected state (IODisconnected).

Source:
../fsio/SPMSocket.h:125
Returns:
true if socket was disconnected, false if diconnect in process.
See Also:
State
Code:
public bool Disconnect ( )

static method EncryptSessionKeys

? ^  < > 
undocumented
Source:
../fsio/SPMSocket.h:471
Code:
public static bool EncryptSessionKeys ( const unsigned char * key ,
unsigned keylen ,
const unsigned char * keydata ,
int keydatasize ,
unsigned char * enckeydata ,
int * enckeydatasize )

method FlushWriteBuffer

? ^  < > 
Try to send pending data.
Source:
../fsio/SPMSocket.h:177
Returns:
true if operation should be repeated to send remaining data.
Code:
public bool FlushWriteBuffer ( )

static method FreeLine

? ^  < > 
Free buffer returned by ReadLine function.
Source:
../fsio/SPMSocket.h:214
Param:
line pointer to the buffer returned by ReadLine function.
Code:
public static void FreeLine ( void * line )

static method GenerateSessionKeys

? ^  < > 
undocumented
Source:
../fsio/SPMSocket.h:467
Code:
public static bool GenerateSessionKeys ( Digest digest ,
Cipher cipher ,
unsigned cipher_key_length ,
unsigned * cipher_key_offset ,
unsigned char * keydata ,
unsigned * keydatasize )

static method getCipherBlockSize

? ^  < > 
Get cipher block size.
Source:
../fsio/SPMSocket.h:458
Param:
ciph cipher type
Returns:
block size for specified cipher type
See Also:
Cipher
Code:
public static int getCipherBlockSize ( Cipher ciph )

static method getCipherKeyLength

? ^  < > 
Get cipher key length.
Source:
../fsio/SPMSocket.h:450
Params:
ciph cipher type
key_len key length (if not fixed for cpecified type)
Returns:
key length for specified cipher type and optional key length
See Also:
Cipher
Code:
public static int getCipherKeyLength ( Cipher ciph ,
unsigned key_len )

method GetClientAddr

? ^  < > 
Get human-readable address of connected client.
Source:
../fsio/SPMSocket.h:150
Returns:
address of the client on the other end of link.
Code:
public const char * GetClientAddr ( ) const

static method getDigestKeyLength

? ^  < > 
Get digest key length.
Source:
../fsio/SPMSocket.h:441
Param:
dgst digest type
Returns:
key length for specified digest type
See Also:
Digest
Code:
public static int getDigestKeyLength ( Digest dgst )

method GetSessionIdleTime

? ^  < > 
Get connect timeout
Source:
../fsio/SPMSocket.h:164
Returns:
time slice for user status update during Connect (in seconds).
Code:
public int GetSessionIdleTime ( ) const

method GetState

? ^  < > 
Get socket state.

Get current state.

Source:
../fsio/SPMSocket.h:308
See Also:
State
Code:
public State GetState ( ) const

method GetWriteBufferSize

? ^  < > 
Get write buffer size.
Source:
../fsio/SPMSocket.h:171
Returns:
send buffer size in bytes - data that was enqueued but not sent yet. This value can be used to detect slow links.
Code:
public size_t GetWriteBufferSize ( ) const

method IsOk

? ^  < > 
Check socket state.
Source:
../fsio/SPMSocket.h:144
Returns:
true if underlying windows socket is Ok and no read/write errors occured.
Code:
public bool IsOk ( ) const

method isSecured

? ^  < > 
Get security state.

Check if security is enabled in the specified direction(s).

Source:
../fsio/SPMSocket.h:433
Param:
sec_dir direction to check
Returns:
true if security enabled
Code:
public bool isSecured ( SecureDirection sec_dir ) const

method Listen

? ^  < > 
Listen for incoming connections.

Socket will be put into the listening state (IOListen). Incoming connections should be accepted with Accept .

Source:
../fsio/SPMSocket.h:104
Params:
port TCP/IP port where to listen for incoming connections.
addr listening address (if no address cpecifyed, socket will listen on all available addresses).
af address family, values other then AF_INET never where tested
type address family, values other then SOCK_STREAM never where tested
protocol 0 by default, which means TCP/IP
See Also:
State
Code:
public bool Listen ( u_short port ,
const char * addr = 0 ,
int af = AF_INET ,
int type = SOCK_STREAM ,
int protocol = 0 )

operator SOCKET

? ^  < > 
Get underlying windows socket.
Source:
../fsio/SPMSocket.h:183
Returns:
underlying windows socket.
Code:
public operator SOCKET ( ) const

method PutBack

? ^  < > 
Rewind read buffer.

Put readen data back to the read buffer and rewind buffer pointer on the specified amount.

Source:
../fsio/SPMSocket.h:222
Params:
buf data to put back.
n size of data.
Code:
public void PutBack ( const char * buf ,
int n )

method Read

? ^  < > 
Read data from sream.
Source:
../fsio/SPMSocket.h:191
Params:
buf data buffer.
n buffer size.
Returns:
number of bytes that were read.
Code:
public int Read ( char * buf ,
int n )

method ReadLine

? ^  < > 
Read next line from stream.

Read all the data from stream until delimiter will be found. If no delimiter found and socket was closed or disconnected, no data will be read. If delimiter was found, it will be extracted from stream but not appended to the string. This routine can block for indefinite amount of time if no delimiter occurs in data stream while the socket remains valid.

Source:
../fsio/SPMSocket.h:207
Params:
size pointer to the location where will be stored number of characters, extracted from stream.
delim end-of-line delimiter, newline ('\n') by default.
Returns:
line which was read from the stream. It shoul be freed with FreeLine function.
Code:
public char * ReadLine ( unsigned * size ,
char delim = '\n' )

method ReadMsg

? ^  < > 
Read message from stream.

Retrieve next message from stream. The message should be checked for validity by MessageType::IsOk . The typical usage of this function looks as follows:

 while(1) (
 	MessageType rdmsg;
 	if(!m_Socket.ReadMsg(rdmsg)) {
 		m_Socket.Close();
 		return -1;
 	}

if(rdmsg.IsOk()) { //..... // process message //..... if(terminate_flag) return 1; } else Sleep(1000); }

Source:
../fsio/SPMSocket.h:270
Params:
M the object where to store retrieved mesage.
readen pointer to the number of bytes actually readen.
Returns:
true if stream is in good state.
See Also:
Close, MessageType::IsOk
Code:
public bool ReadMsg ( MessageType & M ,
unsigned * readen = 0 )

enum SecureDirection

? ^  < > 
Enumerates possible secure modes.

Source:
../fsio/SPMSocket.h:315
Code:
public enum SecureDirection { sNone = 0x0 ,
sRead = 0x1 ,
sWrite = 0x2 ,
sBoth = 0x3 ,
}

method setSecurity

? ^  < > 
Configure security on socket.

Configures encryption and/or message digest on socket. Alocates necessary structures, validates digest and key lengths, and stores key if needed. If digNone specified as digest type, and ciphNone as cipher type, security will be disabled. Encrypted message structure:

Message contains:
Source:
../fsio/SPMSocket.h:425
Params:
sec_dir to which direction to apply parameters below
dgst digest type
dig_key digest key
ciph cipher type
ciphmd cipher mode
ciph_key cipher key data
key_len cipher key data length
ciphpad cipher padding mode
Returns:
true if security was enabled on socket in specified direction
Code:
public bool setSecurity ( SecureDirection sec_dir ,
Digest dgst ,
const unsigned char * dig_key ,
Cipher ciph ,
CipherMode ciphmd ,
const unsigned char * ciph_key ,
unsigned key_len ,
CipherPadding ciphpad )

method SetSessionIdleTime

? ^  < > 
Set connect timeout.
Source:
../fsio/SPMSocket.h:157
Param:
seconds time slice for user status update during Connect .
Code:
public void SetSessionIdleTime ( int seconds )

enum State

? ^  < > 
Enumerates possible socket states.

Source:
../fsio/SPMSocket.h:289
Code:
public enum State { IOError ,
IOListen ,
IOConnect ,
IOWaiting ,
IOShutdown ,
IODisconnected ,
}

method Write

? ^  < > 
Write data to stream.
Source:
../fsio/SPMSocket.h:232
Params:
buf data buffer.
n buffer size.
Returns:
number of bytes that where put to stream or 0 if the socket can't write data. if return value is less than n, operation should be repeated with buf being offset by returned value.
Code:
public int Write ( const char * buf ,
int n )

method WriteLine

? ^  < > 
Write line to stream.
Source:
../fsio/SPMSocket.h:239
Param:
buf zero-delimited string.
Returns:
number of bytes that where put to stream or 0 if the socket can't write data.
Code:
public int WriteLine ( const char * str )

method WriteMsg

? ^  < > 
Write message to stream.

Put message to stream.

Source:
../fsio/SPMSocket.h:280
Params:
M message to send.
written pointer to the size of actually written data (for statistics)
Returns:
true if message was set to stream. If false returned, it means that either message was too big, either stream can't send data.
Code:
public bool WriteMsg ( const MessageType & M ,
unsigned * written = 0 )

(C) Advanced Technologies Center, 2002-2006
For support contact us at fsdev@nanoscopy.net