diff --git a/src/Classes/TcpClient.cls b/src/Classes/TcpClient.cls index 55125f4..a120e20 100644 --- a/src/Classes/TcpClient.cls +++ b/src/Classes/TcpClient.cls @@ -12,6 +12,19 @@ Option Explicit Private m_clientSocket As Long +Public Sub ConnectTo(host As String, port As Long) + Dim address As wsock32.sockaddr_in + address.sin_addr.s_addr = wsock32.inet_addr(host) + address.sin_family = wsock32.AF_INET + address.sin_port = wsock32.htons(port) + + m_clientSocket = wsock32.socket(wsock32.AF_INET, wsock32.SOCK_STREAM, 0) + + Dim connectResult As Long + connectResult = wsock32.connect(m_clientSocket, address, 16) +End Sub + + Public Sub Initialize(ByVal socket As Long) Dim timeout As Long timeout = 500 @@ -49,5 +62,5 @@ End Function Public Sub Dispose() - wsock32.closesocket (m_clientSocket) + wsock32.closesocket m_clientSocket End Sub diff --git a/src/Modules/wsock32.bas b/src/Modules/wsock32.bas index 96bc123..c6afdc1 100644 --- a/src/Modules/wsock32.bas +++ b/src/Modules/wsock32.bas @@ -56,6 +56,7 @@ Public Declare PtrSafe Function WSAStartup Lib "wsock32.dll" (ByVal versionRequi Public Declare PtrSafe Function WSAGetLastError Lib "wsock32.dll" () As Long Public Declare PtrSafe Function WSACleanup Lib "wsock32.dll" () As Long Public Declare PtrSafe Function socket Lib "wsock32.dll" (ByVal addressFamily As Long, ByVal socketType As Long, ByVal protocol As Long) As Long +Public Declare PtrSafe Function connect Lib "wsock32.dll" (ByVal s As Long, ByRef address As sockaddr_in, ByVal namelen As Long) As Long Public Declare PtrSafe Function htons Lib "wsock32.dll" (ByVal hostshort As Long) As Integer Public Declare PtrSafe Function bind Lib "wsock32.dll" (ByVal socket As Long, name As sockaddr_in, ByVal nameLength As Integer) As Long Public Declare PtrSafe Function listen Lib "wsock32.dll" (ByVal socket As Long, ByVal backlog As Integer) As Long @@ -64,6 +65,7 @@ Public Declare PtrSafe Function accept Lib "wsock32.dll" (ByVal socket As Long, Public Declare PtrSafe Function setsockopt Lib "wsock32.dll" (ByVal socket As Long, ByVal level As Long, ByVal optname As Long, ByRef optval As Long, ByVal optlen As Integer) As Long Public Declare PtrSafe Function send Lib "wsock32.dll" (ByVal socket As Long, buffer As String, ByVal bufferLength As Long, ByVal flags As Long) As Long Public Declare PtrSafe Function recv Lib "wsock32.dll" (ByVal socket As Long, ByVal buffer As String, ByVal bufferLength As Long, ByVal flags As Long) As Long +Public Declare PtrSafe Function inet_addr Lib "wsock32.dll" (ByVal hostname As String) As Long Public Declare PtrSafe Function closesocket Lib "wsock32.dll" (ByVal s As Long) As Long