Messing with sockets

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Messing with sockets

Geoffroy Couprie
Hello,

I try to play with sockets in Pharo, and I encounter a strange error.
Here is my code:
|tempsock|
        Socket initialize.
        tempsock := Socket newTCP.
        tempsock listenOn: 12345 backlogSize: 4.
       
        [sock isNil] whileTrue:[sock:= tempsock waitForAcceptFor: 600].
        sock sendCommand: 'Hello world!!'.
        sock ifNotNil:
                [[sock isConnected] whileTrue:
                [[sock waitForDataUntil:2000] ifTrue:
                        [sock sendCommand:'Looping'.
                        sock sendCommand: sock receiveData ].
    ]].
        sock closeAndDestroy.

Once the connection is accepted, an exception is thrown in "sock
waitForDataUntil:2000" by BlockCosure>>mustBeBooleanIn:context. From
what I see, the signal "proceed for truth" is sent, and th debugger
kicks in.

How can I prevent the debugger from starting?

Best regards,

Geoffroy

_______________________________________________
Pharo-users mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-users
Reply | Threaded
Open this post in threaded view
|

Re: Messing with sockets

Stéphane Ducasse

On May 9, 2010, at 2:20 PM, Geoffroy Couprie wrote:

> Hello,
>
> I try to play with sockets in Pharo, and I encounter a strange error.
> Here is my code:
> |tempsock|
> Socket initialize.
> tempsock := Socket newTCP.
> tempsock listenOn: 12345 backlogSize: 4.
>
> [sock isNil] whileTrue:[sock:= tempsock waitForAcceptFor: 600].
> sock sendCommand: 'Hello world!!'.
> sock ifNotNil:
> [[sock isConnected] whileTrue:
> [[sock waitForDataUntil:2000] ifTrue:
> [sock sendCommand:'Looping'.
> sock sendCommand: sock receiveData ].
>     ]].
> sock closeAndDestroy.

Now Geoffroy I think that Socket is not "optimal".

> sock ifNotNil:
> [[sock isConnected] whileTrue:
> [[sock waitForDataUntil:2000] ifTrue:

                        (sock waitForDataUntil: 2000)?

> [sock sendCommand:'Looping'.
> sock sendCommand: sock receiveData ].
>     ]].


> Once the connection is accepted, an exception is thrown in "sock
> waitForDataUntil:2000" by BlockCosure>>mustBeBooleanIn:context. From
> what I see, the signal "proceed for truth" is sent, and th debugger
> kicks in.
>
> How can I prevent the debugger from starting?
>
> Best regards,
>
> Geoffroy
>
> _______________________________________________
> Pharo-users mailing list
> [hidden email]
> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-users


_______________________________________________
Pharo-users mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-users
Reply | Threaded
Open this post in threaded view
|

Re: Messing with sockets

Geoffroy Couprie
Hello,

On Sun, May 9, 2010 at 4:32 PM, Stéphane Ducasse
<[hidden email]> wrote:

>
> On May 9, 2010, at 2:20 PM, Geoffroy Couprie wrote:
>
>> Hello,
>>
>> I try to play with sockets in Pharo, and I encounter a strange error.
>> Here is my code:
>> |tempsock|
>>       Socket initialize.
>>       tempsock := Socket newTCP.
>>       tempsock listenOn: 12345 backlogSize: 4.
>>
>>       [sock isNil] whileTrue:[sock:= tempsock waitForAcceptFor: 600].
>>       sock sendCommand: 'Hello world!!'.
>>       sock ifNotNil:
>>               [[sock isConnected] whileTrue:
>>               [[sock waitForDataUntil:2000] ifTrue:
>>                       [sock sendCommand:'Looping'.
>>                       sock sendCommand: sock receiveData ].
>>       ]].
>>       sock closeAndDestroy.
>
> Now Geoffroy I think that Socket is not "optimal".
>

What should I use then? Is it possible to have non-blocking read on sockets?

>> sock ifNotNil:
>>               [[sock isConnected] whileTrue:
>>               [[sock waitForDataUntil:2000] ifTrue:
>
>                        (sock waitForDataUntil: 2000)?
>

Thank you, it worked :)

Best regards,

Geoffroy

_______________________________________________
Pharo-users mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-users
Reply | Threaded
Open this post in threaded view
|

Re: Messing with sockets

Stéphane Ducasse

On May 9, 2010, at 4:40 PM, Geoffroy Couprie wrote:

> Hello,
>
> On Sun, May 9, 2010 at 4:32 PM, Stéphane Ducasse
> <[hidden email]> wrote:
>>
>> On May 9, 2010, at 2:20 PM, Geoffroy Couprie wrote:
>>
>>> Hello,
>>>
>>> I try to play with sockets in Pharo, and I encounter a strange error.
>>> Here is my code:
>>> |tempsock|
>>>       Socket initialize.
>>>       tempsock := Socket newTCP.
>>>       tempsock listenOn: 12345 backlogSize: 4.
>>>
>>>       [sock isNil] whileTrue:[sock:= tempsock waitForAcceptFor: 600].
>>>       sock sendCommand: 'Hello world!!'.
>>>       sock ifNotNil:
>>>               [[sock isConnected] whileTrue:
>>>               [[sock waitForDataUntil:2000] ifTrue:
>>>                       [sock sendCommand:'Looping'.
>>>                       sock sendCommand: sock receiveData ].
>>>       ]].
>>>       sock closeAndDestroy.
>>
>> Now Geoffroy I think that Socket is not "optimal".
>>
>
> What should I use then? Is it possible to have non-blocking read on sockets?

I'm quite bad with network too :)
But one day we will have to fix the examples and the code in network.

>
>>> sock ifNotNil:
>>>               [[sock isConnected] whileTrue:
>>>               [[sock waitForDataUntil:2000] ifTrue:
>>
>>                        (sock waitForDataUntil: 2000)?
>>
>
> Thank you, it worked :)
>
> Best regards,
>
> Geoffroy
>
> _______________________________________________
> Pharo-users mailing list
> [hidden email]
> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-users


_______________________________________________
Pharo-users mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-users
Reply | Threaded
Open this post in threaded view
|

Re: Messing with sockets

Igor Stasenko
In reply to this post by Stéphane Ducasse
On 9 May 2010 17:32, Stéphane Ducasse <[hidden email]> wrote:

>
> On May 9, 2010, at 2:20 PM, Geoffroy Couprie wrote:
>
>> Hello,
>>
>> I try to play with sockets in Pharo, and I encounter a strange error.
>> Here is my code:
>> |tempsock|
>>       Socket initialize.
>>       tempsock := Socket newTCP.
>>       tempsock listenOn: 12345 backlogSize: 4.
>>
>>       [sock isNil] whileTrue:[sock:= tempsock waitForAcceptFor: 600].
>>       sock sendCommand: 'Hello world!!'.
>>       sock ifNotNil:
>>               [[sock isConnected] whileTrue:
>>               [[sock waitForDataUntil:2000] ifTrue:
>>                       [sock sendCommand:'Looping'.
>>                       sock sendCommand: sock receiveData ].
>>       ]].
>>       sock closeAndDestroy.
>
> Now Geoffroy I think that Socket is not "optimal".
>
>> sock ifNotNil:
>>               [[sock isConnected] whileTrue:
>>               [[sock waitForDataUntil:2000] ifTrue:
>
seems like #waitForDataUntil: could answer not only false or true, but
also a nil.
Just do it like that:

                        (sock waitForDataUntil: 2000) == true ifTrue: [
>
                      [sock sendCommand:'Looping'.
                      sock sendCommand: sock receiveData ] ].

>>       ]].
>
>
>> Once the connection is accepted, an exception is thrown in "sock
>> waitForDataUntil:2000" by BlockCosure>>mustBeBooleanIn:context. From
>> what I see, the signal "proceed for truth" is sent, and th debugger
>> kicks in.
>>
>> How can I prevent the debugger from starting?
>>
>> Best regards,
>>
>> Geoffroy
>>
>> _______________________________________________
>> Pharo-users mailing list
>> [hidden email]
>> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-users
>
>
> _______________________________________________
> Pharo-users mailing list
> [hidden email]
> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-users
>



--
Best regards,
Igor Stasenko AKA sig.

_______________________________________________
Pharo-users mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-users