Hi Hilaire,

Given the following comment:

Socket>>#primSocket: socketID receiveUDPDataInto: aStringOrByteArray 
startingAt: startIndex count: count
        "Receive data from the given socket into the given array starting at 
the given index. 
        Return an Array containing the amount read, the host address byte 
array, the host port, and the more flag"

        <primitive: 'primitiveSocketReceiveUDPDataBufCount' module: 
'SocketPlugin'>
        self primitiveFailed

I would says that the primitive result uses a ByteArray to represent the (other 
party's) host address in its second slot.

I find the method Socket>>#receiveDataInto:fromHost:port: quite weird: why 
would you restrict from whom you receive datagrams, especially since 
non-matching datagrams are simply thrown away.

But I do agree that SocketAddress is a weird class, maybe its #species should 
be set to ByteArray so that #= would work between them, but I am not sure.

Sven 

> On 19 Jan 2020, at 20:24, HilaireFernandes <hila...@drgeo.eu> wrote:
> 
> Hello,
> 
> I would like to discuss one point regarding this method. In my opinion its
> parameter hostAddress is expected to be a SocketAdress, but the method
> interprets it as a ByteArray. So in the code bellow, the returned result is
> 0, although the host responds a datagram:
> 
> server := NetNameResolver addressForName: 'localhost'.
> socket := Socket newUDP.
> socket sendUDPData: packet toHost: server port: 30000.
> socket waitForData.
> packet := ByteArray new: 200.
> result := socket receiveDataInto: packet fromHost: server port: 30000.
> 
> The method receiveUDPData:toHost:port: should be amended as follow to make
> it symmetric with sendUDPData... :
> 
>       [ | datagram |
>               datagram := self receiveUDPDataInto: aStringOrByteArray.
>               ((datagram at: 2) *asSocketAddress* = hostAddress and: [ 
> (datagram at: 3)
> = portNumber ]) 
>                       ifTrue: [ ^ datagram at: 1 ]
>                       ifFalse: [ ^0 ] ] repeat
> 
> What do you think?
> 
> 
> 
> -----
> http://drgeo.eu
> --
> Sent from: http://forum.world.st/Pharo-Smalltalk-Developers-f1294837.html
> 


Reply via email to