[Gambas-user] Net Socket timing issue?

Eric Budd ericbudd at ...407...
Wed Jan 19 15:46:29 CET 2005


Thanks so much for your help!  Sorry it took me a while to get back, 
been busy :P

Your suggestion worked, for the most part.  I put the while loop in on 
the socket _Read event.  I also put in a loop in the write sub, waiting 
for the "HasRead" boolean value, since I know that I will have data 
immediately after a write.  The code looks like this:

Public Sub Write(Data as String)
    HasRead = False
    WRITE #sM, Data & Chr(10), Len(Data) + 1
    WHILE HasRead = False
       Wait(0.1)
    WEND
End

Public SUB MySocket_Read()
    READ #sM, LastBuf, Lof(sM)
    WHILE Lof(sM) <> 0
       Wait(0.1)
    WEND
    FullBuf = FullBuf & LastBuf
    HasRead = True
End

It works, except when the server returns a lot of data very fast (i.e. 
looking up help files and such); the client chops off bits of the 
returned data, but it's good enough for what I want to do right now, and 
it saves me having to write really rich socket-handling code :)

Thanks again for your help!

E. Budd

Daniel Campos wrote:

> ericbudd at ...407... escribió:
>
>> I tried your suggestion, which was interesting, because Ihad been 
>> concentrating on the "read" portion of the code.  HoweverI am still 
>> having the problem.  I did discover something interesting that may 
>> make it easier, tho...
>>
>> In my socket wrapper class, I have the following code on the 
>> MySocket_Read event:
>>
>>  READ #sM, LastBuf, Lof(sM)
>>  frmMain.txtConsole.Text = frmMain.txtConsole.Text & LastBuf
>>
>> On the frmMain, the button which sends the command has the following 
>> code:
>>
>>  sockMUSH.Write(ME.txtCommand.Text & Chr(10))
>>  txtConsole.Selection(Len(txtConsole.Text), 0) ' this line moves to 
>> the bottom of the display area
>>
>>  So the button is clicked, the command is written, the console is 
>> correctly updated, but not until AFTER the selection command.  The 
>> code finishes executing before any data comes back on the port.
>>
>>  Is there a way I can force the program to wait until a read has 
>> occurred and finished before continuing?
>>
>> Thanks so much!
>>
>>
>>  
>>
> The Socket class is non-blocking, so the only way to wait is writting 
> a loop:
>
> Do While Lof(sM)=0
>    WAIT (0.1)  ' or the time you want :-)
> Loop
>
> Regards,
>
> D. Campos
>
>
>
>
>
> -------------------------------------------------------
> The SF.Net email is sponsored by: Beat the post-holiday blues
> Get a FREE limited edition SourceForge.net t-shirt from ThinkGeek.
> It's fun and FREE -- well, almost....http://www.thinkgeek.com/sfshirt
> _______________________________________________
> Gambas-user mailing list
> Gambas-user at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-user
>





More information about the User mailing list