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