 |

04-14-2008, 08:32 AM
|
|
Junior Contributor
|
|
Join Date: Dec 2004
Location: Canada
Posts: 225
|
|
FD_ACCEPT... Accept()
|
Hello, i am hooking my form to receive messages, so i may look for winsock messages sent to my window for my socket.
I am looking for the FD_ACCEPT message, so I may connect.
I first create a socket with socket()
I then bind()
I then listen, and wait for FD_ACCEPT.
When FD_Accept does come,it just seems loop, or freeze the window. Here is code:
Code:
Public Sub HookForm(F As Form)
PrevProc = SetWindowLong(F.hwnd, GWL_WNDPROC, AddressOf WindowProc)
End Sub
Public Sub UnHookForm(F As Form)
If PrevProc <> 0 Then
SetWindowLong F.hwnd, GWL_WNDPROC, PrevProc
PrevProc = 0
End If
End Sub
Public Function WindowProc(ByVal hwnd As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
If uMsg = WINSOCKMSG Then
ProcessMessage wParam, lParam
Else
WindowProc = CallWindowProc(PrevProc, hwnd, uMsg, wParam, lParam)
End If
End Function
Public Sub ProcessMessage(ByVal lFromSocket As Long, ByVal lParam As Long)
Dim X As Long, ReadBuffer(1 To 1024) As Byte, strCommand As String
Dim sockin As sockaddr
Select Case lParam
Case FD_ACCEPT
Dim tmpSockAddr As sockaddr
Dim tmpSocket As Long
tmpSockAddr = saZero
tmpSocket = accept(lFromSocket, tmpSockAddr, Len(tmpSockAddr))
Msgbox "incoming!" <--repeats itself again and again
End Select
End Sub
Function ConnectSock(ByVal Host, ByVal Port&, retIpPort$, ByVal HWndToMsg&, ByVal Async%) As Long
Dim SelectOps&, Dummy&
Dim s As Long
Dim sockin As sockaddr
sockin = saZero
SockReadBuffer$ = ""
sockin = saZero
sockin.sin_family = AF_INET
sockin.sin_port = htons(777)
sockin.sin_addr = asc_to_long("172.16.16.20"
s = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)
bind s, sockin, sockaddr_size
listen s, 10
SelectOps = FD_ACCEPT
WSAAsyncSelect s, HWndToMsg, ByVal 1025, ByVal SelectOps
ConnectSock = s
End Function
Function asc_to_long(ByVal asc_ip As String) As Long
asc_to_long = inet_addr(asc_ip)
'MsgBox "connecting to " & getascip(asc_to_long)
End Function
I initiate the connection to the server using telnet 172.16.16.20 777
|
|

04-15-2008, 06:58 AM
|
|
Newcomer
|
|
Join Date: Mar 2008
Posts: 20
|
|
|
Believe that at that point, you also need to close the listening socket. Also, msgbox is nasty means of checking that something happened, you're better off using something else which does not require interaction, like perhaps another form with a listbox which displays each action in the order they occur.
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
|