CSocketMaster

CSocketMaster


Winsock api implementation class.
Requires modSocketMaster.bas code module.


Version: 1.3
Author: Copyright (c) 2004 by Emiliano Scavuzzo. Rosario, Argentina
Based on CSocket by Oleg Gdalevich
Subclassing based on WinSubHook2 by Paul Caton
Modified: 04/02/2005

Public:

Types:

NameDescription
 SockState 

Properties:

NameDescription
 BytesReceived (get) 
 LocalPort (get) 
 LocalPort (let) 
 SocketHandle (get) 
 State (get) 

Methods:

NameDescription
 Accept 
 Bind 
 CloseSck 
 GetData 
 Listen 
 SendData 
 WndProc This sub receives system messages from our WndProc.
This sub MUST be the first on the class. DO NOT attempt
to change its location or the code will CRASH. 

Events:

NameDescription
 CloseSck 
 Connect 
 ConnectionRequest 
 DataArrival 
 Error 
 SendComplete 
 SendProgress 

Private:

CSocketMaster

NameDescription
 Class_Initialize 
 Class_Terminate 

Constants:

NameDescription
 AF_INET 
 IPPROTO_TCP 
 SO_RCVBUF 
 SO_SNDBUF 
 SOCK_DGRAM 
 SOCK_STREAM 
 SOL_SOCKET 

Types:

NameDescription
 HOSTENT 
 sockaddr_in 

Properties:

NameDescription
 m_blnAcceptClass If True then this is an Accept socket class 
 m_colWaitingResolutions hosts waiting to be resolved by the system 
 m_enmState socket state 
 m_lngLocalPort local port 
 m_lngLocalPortBind temporary local port 
 m_lngMemoryHandle buffer memory handle 
 m_lngMemoryPointer memory pointer used as buffer when resolving host 
 m_lngRecvBufferLen winsock buffer size for receives 
 m_lngRemotePort remote port 
 m_lngSendBufferLen winsock buffer size for sends 
 m_lngSocketHandle socket handle 
 m_strLocalIP local IP 
 m_strRecvBuffer local outgoing buffer 
 m_strRemoteHost remote host 
 m_strRemoteHostIP remote host ip 
 m_strSendBuffer local incoming buffer 
 m_strTag tag 

Methods:

NameDescription
 BindInternal This function binds a socket to a local port and IP.  
 BuildArray Returns a byte array of Size bytes filled with incoming buffer data.  
 CleanResolutionSystem Clean resolution system that is in charge of asynchronous hostname resolutions. 
 ConnectToIP Connect to a given 32 bits long ip  
 DestroySocket Destroys the socket if it exists and unregisters it from control list. 
 FreeMemory Free memory allocated by AllocateMemory 
 GetLocalInfo Retrieves local info from a connected socket.  
 GetLocalPort Returns local port from a connected or bound socket.

 

 GetRemoteInfo Retrieves remote info from a connected socket.  
 PostResolution When the system resolves a hostname in asynchronous way we call this function to decide what to do with the result.  
 PostSocket This procedure is called by the WindowProc callback function.  
 ProcessOptions Retrieves some socket options. If it is an UDP socket also sets SO_BROADCAST option. 
 RecvData This function is to retrieve data from the buffer. If we are using TCP then the data is retrieved from a local buffer (m_strRecvBuffer). If we are using UDP the data is retrieved from winsock buffer. This function returns number of bytes received, and move data from the buffer into the data argument. MOVE means that data will be removed from the buffer.  
 RecvDataToBuffer This function retrieves data from the Winsock buffer into the class local buffer.  
 ResolveIfHostnameSync Resolves a host (if necessary) in synchronous way If succeeds returns a 32 bits long IP, strHostIP = readable IP string and lngErrorCode = 0 If fails returns vbNull, strHostIP = vbNullString and lngErrorCode <> 0  
 SendBufferedData Send buffered data if we are using TCP protocol. 
 SocketExists Tries to create a socket if there isnt one yet and registers it to the control list.  

Declarations:

NameDescription
 api_accept (function) 
 api_bind (function) 
 api_closesocket (function) 
 api_connect (function) 
 api_gethostbyname (function) 
 api_getpeername (function) 
 api_getsockname (function) 
 api_htons (function) 
 api_inet_addr (function) 
 api_inet_ntoa (function) 
 api_listen (function) 
 api_ntohs (function) 
 api_recv (function) 
 api_send (function) 
 api_setsockopt (function) 
 api_socket (function) 
 api_WSACancelAsyncRequest (function) 

Requirements

1.3