Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > Communications > FD_ACCEPT... Accept()


Reply
 
Thread Tools Display Modes
  #1  
Old 04-14-2008, 08:32 AM
jimmay jimmay is offline
Junior Contributor
 
Join Date: Dec 2004
Location: Canada
Posts: 225
Default 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
Reply With Quote
  #2  
Old 04-15-2008, 06:58 AM
Dreamles Dancer Dreamles Dancer is offline
Newcomer
 
Join Date: Mar 2008
Posts: 20
Default

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.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->