Code by Johh MacIntosh of 2000 in squeak 5.2�� is below, for the primitiveOnlySupportsOneSemaphore=true it relies on #setPeer:port which in turn does a linux syscall to connect(2)�� restricting socket to send/receive only to/from a single peer.
in 2011 it was changed by 'ul' (I don't know whom the initials belong to) setPeer:port was dropped and this is how it stays since then both in squeak and pharo - purely image side logic to filter incoming datagrams.
= JMM =
receiveDataInto: aStringOrByteArray fromHost: hostAddress port: portNumber
| datagram |
"Receive a UDP packet from the given hostAddress/portNumber, storing the data in the given buffer, and return the number of bytes received. Note the given buffer may be only partially filled by the received data."
primitiveOnlySupportsOneSemaphore ifTrue:
[self setPeer: hostAddress port: portNumber.
^self receiveDataInto: aStringOrByteArray].
[true] whileTrue:
[datagram := self receiveUDPDataInto: aStringOrByteArray.
((datagram at: 2) = hostAddress and: [(datagram at: 3) = portNumber])
ifTrue: [^datagram at: 1]
ifFalse: [^0]]
= ul =
receiveDataInto: aStringOrByteArray fromHost: hostAddress port: portNumber
| datagram |
"Receive a UDP packet from the given hostAddress/portNumber, storing the data in the given buffer, and return the number of bytes received. Note the given buffer may be only partially filled by the received data."
[
datagram := self receiveUDPDataInto: aStringOrByteArray.
((datagram at: 2) = hostAddress and: [(datagram at: 3) = portNumber])
ifTrue: [^datagram at: 1]
ifFalse: [^0]] repeat