{****************************************************************************
** **
** PSSDK HNTcpSession module **
** Copyright (c) 1997 - 2007 microOLAP Technologies LTD, **
** Khalturin A.P., Naumov D.A. **
** **
****************************************************************************}
unit HNTcpSession;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
HNPSManager, HNPsSdkDef;
type
//---------------------------------------------------------------------------
// Class THNTcpSession
//---------------------------------------------------------------------------
THNTcpSession = class
private
hTcpSes : Pointer;
private
function GetState: DWORD;
function GetCloseReason: DWORD;
function GetCreateTime: DWORD;
function GetLastPacketTime: DWORD;
function GetClientIP: DWORD;
function GetClientPort: WORD;
function GetServerIP: DWORD;
function GetServerPort: WORD;
function GetUserData: Pointer;
procedure SetUserData(UserData : Pointer);
// Add in 3.1
function GetType() : DWORD;
protected
public
constructor Create();
destructor Destroy(); override;
property State: DWORD read GetState;
property CloseReason: DWORD read GetCloseReason;
property CreateTime: DWORD read GetCreateTime;
property LastPacketTime: DWORD read GetLastPacketTime;
property ClientIP: DWORD read GetClientIP;
property ClientPort: WORD read GetClientPort;
property ServerIP: DWORD read GetServerIP;
property ServerPort: WORD read GetServerPort;
property Handle: Pointer read hTcpSes write hTcpSes;
property UserData: Pointer read GetUserData write SetUserData;
// Add in 3.1
property SessionType: DWORD read GetType;
public
function IsValid: BOOL;
function Get_ClientPacketsCount(HiValue: PUINT): UINT;
function Get_ServerPacketsCount(HiValue: PUINT): UINT;
function Get_ClientDataSize(HiValue: PUINT): UINT;
function Get_ServerDataSize(HiValue: PUINT): UINT;
// Add in 2.4
procedure SwapClientServer();
// Add in 3.1
function GetClientIPv6(pIpAddr : Pointer; BufferSize : DWORD) : DWORD;
function GetServerIPv6(pIpAddr : Pointer; BufferSize : DWORD) : DWORD;
published
end;
implementation
{$INCLUDE 'HNPsSdkFun.pas'}
//---------------------------------------------------------------------------
// Create - Consructor
//---------------------------------------------------------------------------
constructor THNTcpSession.Create();
begin
hTcpSes := nil;
end;
//---------------------------------------------------------------------------
// Destroy - Destructor
//---------------------------------------------------------------------------
destructor THNTcpSession.Destroy();
begin
end;
//---------------------------------------------------------------------------
// Method - IsValid - Checks if the HNTcpSession object has been created correctly.
//---------------------------------------------------------------------------
function THNTcpSession.IsValid: BOOL;
begin
Result := BOOL(hTcpSes <> nil);
end;
//---------------------------------------------------------------------------
// Property - State - Returns the TCP session state.
//---------------------------------------------------------------------------
function THNTcpSession.GetState(): DWORD;
begin
Result := TcpSesGetState(hTcpSes);
end;
//---------------------------------------------------------------------------
// Property - CloseReason - Returns the reason why the TCP session has been closed.
//---------------------------------------------------------------------------
function THNTcpSession.GetCloseReason: DWORD;
begin
Result := TcpSesGetCloseReason(hTcpSes);
end;
//---------------------------------------------------------------------------
// Property - CreateTime - Returns the TCP session creation time.
//---------------------------------------------------------------------------
function THNTcpSession.GetCreateTime: DWORD;
begin
Result := TcpSesGetCreateTime(hTcpSes);
end;
//---------------------------------------------------------------------------
// Property - LastPacketTime - Returns the time of receiving of the last packet participated in TCP connection.
//---------------------------------------------------------------------------
function THNTcpSession.GetLastPacketTime: DWORD;
begin
Result := TcpSesGetLastPacketTime(hTcpSes);
end;
//---------------------------------------------------------------------------
// Property - ClientIP - Returns IP address of the client participating in the connection.
//---------------------------------------------------------------------------
function THNTcpSession.GetClientIP: DWORD;
begin
Result := TcpSesGetClientIP(hTcpSes);
end;
//---------------------------------------------------------------------------
// Property - ClientPort - Returns port number of the client participating in the connection.
//---------------------------------------------------------------------------
function THNTcpSession.GetClientPort: WORD;
begin
Result := TcpSesGetClientPort(hTcpSes);
end;
//---------------------------------------------------------------------------
// Property - ServerIP - Returns IP address of the server participating in the connection.
//---------------------------------------------------------------------------
function THNTcpSession.GetServerIP: DWORD;
begin
Result := TcpSesGetServerIP(hTcpSes);
end;
//---------------------------------------------------------------------------
// Property - ServerPort - Returns port number of the server participating in the connection.
//---------------------------------------------------------------------------
function THNTcpSession.GetServerPort: WORD;
begin
Result := TcpSesGetServerPort(hTcpSes);
end;
//---------------------------------------------------------------------------
// Property - UserData - Returns user-defined value associated with TCP session.
//---------------------------------------------------------------------------
function THNTcpSession.GetUserData: Pointer;
begin
Result := TcpSesGetUserData(hTcpSes);
end;
//---------------------------------------------------------------------------
// Property - UserData - Sets user-defined value associated with TCP session.
//---------------------------------------------------------------------------
procedure THNTcpSession.SetUserData(UserData : Pointer);
begin
TcpSesSetUserData(hTcpSes,UserData);
end;
//---------------------------------------------------------------------------
// Method - Get_ClientPacketsCount - Returns the number of packets sent by client.
//---------------------------------------------------------------------------
function THNTcpSession.Get_ClientPacketsCount(HiValue: PUINT): UINT;
begin
Result := TcpSesGetClientPacketsCount(hTcpSes,PDWORD(HiValue));
end;
//---------------------------------------------------------------------------
// Method - Get_ServerPacketsCount - Returns the number of packets sent by server.
//---------------------------------------------------------------------------
function THNTcpSession.Get_ServerPacketsCount(HiValue: PUINT): UINT;
begin
Result := TcpSesGetServerPacketsCount(hTcpSes,PDWORD(HiValue));
end;
//---------------------------------------------------------------------------
// Method - Get_ClientDataSize - Returns the size of data sent by client
//---------------------------------------------------------------------------
function THNTcpSession.Get_ClientDataSize(HiValue: PUINT): UINT;
begin
Result := TcpSesGetClientDataSize(hTcpSes,PDWORD(HiValue));
end;
//---------------------------------------------------------------------------
// Method - Get_ServerDataSize - Returns the size of data sent by server.
//---------------------------------------------------------------------------
function THNTcpSession.Get_ServerDataSize(HiValue: PUINT): UINT;
begin
Result := TcpSesGetServerDataSize(hTcpSes,PDWORD(HiValue));
end;
//---------------------------------------------------------------------------
// Method - SwapClientServer - Swap client/server properties.
//---------------------------------------------------------------------------
procedure THNTcpSession.SwapClientServer();
begin
TcpSesSwapClientServer(hTcpSes);
end;
//---------------------------------------------------------------------------
// v3.1 - TcpSesGetType - Returns the TCP session type.
//---------------------------------------------------------------------------
function THNTcpSession.GetType() : DWORD;
begin
Result := TcpSesGetType(hTcpSes);
end;
//---------------------------------------------------------------------------
// v3.1 - TcpSesGetClientIPv6 - Returns IPv6 address of the client participating in the connection.
//---------------------------------------------------------------------------
function THNTcpSession.GetClientIPv6(pIpAddr : Pointer; BufferSize : DWORD) : DWORD;
begin
Result := TcpSesGetClientIPv6(hTcpSes,pIpAddr,BufferSize);
end;
//---------------------------------------------------------------------------
// v3.1 - TcpSesGetServerIPv6 - Returns IPv6 address of the server participating in the connection.
//---------------------------------------------------------------------------
function THNTcpSession.GetServerIPv6(pIpAddr : Pointer; BufferSize : DWORD) : DWORD;
begin
Result := TcpSesGetServerIPv6(hTcpSes,pIpAddr,BufferSize);
end;
end.