|
-
Aug 14th, 2000, 02:45 PM
#1
Thread Starter
New Member
Hello everyone, this is my first post here 
I am currently writing a Client/Server application. The client is written in visual basic 6 and runs under windows (of course), the server is written in C and is running on a linux box. My question revolves around how to handle a disparity between the way these two process data. In C under linux (and most systems), a recv() call is blocking. So it sits there until the data is sent. So if I called
bytes_recvd = recv(socket, &someint, sizeof(int)); It would
wait at that line of code until something is sent to the system. This is perfect for what I'm trying to do, where you send something, wait for a response, send something, wait for a response, etc... In VB, however, receipt of data triggers the DataArrival event, but the code runs happily along until this even occurs. Well, this poses a problem because what if I wanted to handle multiple receives and then send all those blocks of data to one function for processing? So say the server sent to the client in three separate sends:
Server->SENDING_USERID (a simple integer message)
Server->"username"
Server->"password"
In this case the DataArrival would be called three times, this wouldn't be a problem with blocking I/O, because you could do:
Winsock.GetData message
If message = SENDING_USERID Then
.....Winsock.GetData username
.....Winsock.GetData password
.....SubToHandleData(username, password)
End If
But the way VB works I can't do this without state variables and other crap. Is there another way to implement a form of blocking I/O, or am I coming at this all wrong? Visual Basic uses OO and event driven paradigms that I haven't quite gotten the hand of yet. If anybody can give me any tips it would be very helpful. Alsi I'll give more clarification if needed.
Thanks 
-
Aug 15th, 2000, 01:45 PM
#2
Fanatic Member
you could do this
Code:
Public DataHere as Boolean
'Code
'Stop Point
Do while not DataHere
DoEvents
Loop
Winsock1.GetData(data)
if data = SENDING_USERID then
Winsock1.GetData(username)
Winsock1.GetData(password)
SubToHandleData(username,password)
DataHere = False
end if
end if
'Event
Private Sub Winsock1_DataArival(bytesTotal as integer)
DataHere=True
End Sub
Havn't tried it, but you might want to
GWDASH
[b]VB6, Perl, ASP, HTML, JavaScript, VBScript, SQL, C, C++, Linux , Java, PHP, MySQL, XML[b]
-
Aug 15th, 2000, 02:29 PM
#3
Thread Starter
New Member
Thanks
That's a nifty idea! I never thought about it that way but it seems like it would work.
It seems a little kludgey though. Like the principle itself is sound yet maybe it's just a way to postpone doing it the "right" way. But I think that it should be sufficient for my purposes.
Thank you
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|