PDA

Click to See Complete Forum and Search --> : Listen...


tumblingdown
Jan 31st, 2001, 02:17 AM
Can someone enlighten me on how, when using the winsock api, you are notified when you have incoming data (i.e. when you're listening) ?



td.

tumblingdown
Feb 1st, 2001, 12:47 AM
Ok, maybe i wasn't specific enough. I want to know how, when you using the Winsock API Listen method, how the data arrival/ connection requested events (etc) are reflected.


Cheers.

td.

tumblingdown
Feb 3rd, 2001, 02:08 AM
Anyone?

Feb 3rd, 2001, 03:13 AM
There is a Winsock API example here (http://www.vbapi.com/ref/r/recv.html). It downloads a page from a HTTP server. Or in short, the Winsock API does not seem to be event driven. Rather,


' Make the socket non-blocking, so calls to recv don't halt the program waiting for input.
retval = ioctlsocket(sock, FIONBIO, 1)

' Read the response from the other system. A more sophisticated program
' would watch to see if the connection ever times out (i.e., if the connection is
' lost). For brevity, such code is omitted here.
Do
buffer = Space(4096)
retval = recv(sock, ByVal buffer, Len(buffer), 0)
If retval <> 0 And retval <> SOCKET_ERROR Then
reply = reply & Left(buffer, retval)
End If
' Process background events so the program doesn't appear to freeze.
DoEvents
Loop Until retval = 0


The above code is from the page at vbapi.com in the link above.

tumblingdown
Feb 3rd, 2001, 03:40 AM
For a client, this is fine. I need the process for a Server. It has to listen for new connections etc. How are incoming connections/requests reflected the the server proggy?


td.

Feb 3rd, 2001, 06:40 AM
If you know C literate people, you might want them to translate the listen (http://msdn.microsoft.com/library/default.asp?URL=/library/psdk/winsock/wsapiref_07hu.htm) and accept (http://msdn.microsoft.com/library/default.asp?URL=/library/psdk/winsock/wsapiref_13aq.htm) page at MSDN for you cause it sure beats me!

Feb 12th, 2001, 05:34 PM
If you want to know how to use the DataArrival and ConnectionRequest events, here ya go. I didn't really understand what you were asking

tumblingdown

Private Sub WinSockServer_DataArrival(ByVal bytesTotal As Long)
On Error Resume Next
Dim cString As String

WinSockServer.GetData cString 'Assign incoming data to cString

'Process data in cString example
If Left(cString, 6) = "MsgBox" Then
MsgBox Mid(cString, 6)
End If
End Sub

Private Sub WinSockServer_ConnectionRequest(ByVal requestID As Long)
WinSockServer.Accept requestID
End Sub

tumblingdown
Feb 13th, 2001, 02:00 AM
Please. Read my question. I am not using a Control. I wish to do this using the API. Let me phrase the question another way.

How do you make an object from an external lib (in this case winsock) hook to your (vb's) Event Sink?


td.

(i suspect it cannot be done)

Feb 13th, 2001, 01:45 PM
Maybe you can. I havn't tried this, but it sounds logical.

When I run around the internet, I sometimes use several IE windows to access two different accounts on the same server. This doesn't work if the server used cookies to transfer information, but it does in other cases.

How can I do that? The server is seeing my ip address and two different port numbers. That is how I suspect it tells the difference. If I'm right you could therefore use the API to listen and send messages on the same port and you would be fine. If you listen on port 12345, you have to send data on port 12345.

tumblingdown
Feb 14th, 2001, 01:19 AM
Pardon? Sorry, i don't see the relevance to the question.


td.