Am 06.02.2012 um 23:13 schrieb Eagle Offshore:

> Thanks, I found this but it pretty well ignores UDP other than mentioning it 
> exists.
> 
I think you might confuse the host and port portions of it. If you use

socket receiveDataInto:fromHost:port:

then the host and the port are the ones of the sending side. You need to 
specify your own side as well

| localPort sourceAddress sourcePort buffer receivedBytes socket delay |
localPort := 5000.
sourceAddress := NetNameResolver addressFromString: '255.255.255.255'.
sourcePort := 4848.

buffer := ByteArray new: 1000.
delay := Delay forMilliseconds: 50.

socket := Socket newUDP setPort: localPort.
[[ receivedBytes := socket receiveDataInto: buffer fromHost: sourceAddress 
port: sourcePort.
 receivedBytes isZero ] whileTrue: [ delay wait ]]
        ensure: [ socket closeAndDestroy].

Or you are better off testing it by using #receiveDataInto: instead of 
#receiveDataInto:fromHost:port:

Norbert

> 
> On Feb 6, 2012, at 1:38 PM, jannik.laval wrote:
> 
>> Hi Todd,
>> 
>> The socket chapter in writing progress could help you: 
>> https://gforge.inria.fr/scm/viewvc.php/*checkout*/PharoByExampleTwo-Eng/Sockets/Sockets.pdf?root=pharobooks
>> I do not remember if the receiveData method is blocking. If not, you should 
>> wait til data arrives.
>> 
>> Cheers,
>> Jannik
>> 
>> On Feb 6, 2012, at 22:22 , Eagle Offshore wrote:
>> 
>>> I'm trying to build a display for some instruments that multicast readings 
>>> using UDP.  I started out using CocoaAsyncSocket on Mac 
>>> (https://github.com/robbiehanson/CocoaAsyncSocket) and I have to say it has 
>>> a really wonderful api - would be worth cloning it.
>>> 
>>> However, want to do the same thing in Pharo so I have typed this little 
>>> snippet into the workspace:
>>> 
>>> [| socket |
>>> socket := Socket newUDP.
>>> 10 timesRepeat: [| s |
>>>     s := String new. 
>>>     socket receiveDataInto: s fromHost: (NetNameResolver 
>>> addressFromString:'255.255.255.255' ) port: 4848.
>>>     Transcript show: s.]] fork
>>> 
>>> and it doesn't seem to do anything.
>>> 
>>> What have I missed?  Pharo 1.3 stable on SnowLeopard BTW.
>>> 
>>> Thanks,
>>> -Todd Blanchard
>>> 
>> 
>> ---
>> Jannik Laval
>> 
>> 
> 
> 


Reply via email to