Skip to content

Commit

Permalink
allow connecting to server sockets
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelneu committed May 8, 2019
1 parent e6cc649 commit fcc0956
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/Classes/TcpClient.cls
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -49,5 +62,5 @@ End Function


Public Sub Dispose()
wsock32.closesocket (m_clientSocket)
wsock32.closesocket m_clientSocket
End Sub
2 changes: 2 additions & 0 deletions src/Modules/wsock32.bas
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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


Expand Down

0 comments on commit fcc0956

Please sign in to comment.