Thanks for the tips. So far, I've found two ways to write the datagram. One with stream, the other one with hexadecimal representation.
The former is verbose but helps for the clarity. The latter is shorter while tricky when variable content need to be inserted in the datagram Are they better way to write the datagram? Thanks Hilaire --------------------8<---------------------- | server socket packet result | packet := ByteArray streamContents: [ :str | str uint32: 16r4F457403; uint16: 0; nextPut: 0; nextPut: 3; uint16: 65500; nextPut: 1]. "Shorted but not as readable" packet := ByteArray readHexFrom: '4F45740300000003FFDC01'. server := NetNameResolver addressForName: 'localhost'. socket := Socket newUDP setPort: 30000; yourself. socket sendUDPData: packet toHost: server port: 30000. socket waitForDataFor: 1. packet := ByteArray new: 200. result := socket receiveUDPDataInto: packet. result first isZero ifFalse: [ | peerId | peerId := packet unsignedShortAt: 13 bigEndian: true. UIManager default inform: 'Connected to Minetest server, peer id: ', peerId asString. "Disconnect" packet := ByteArray streamContents: [ :str | str uint32: 16r4F457403; uint16: peerId; nextPut: 0; nextPut: 0; nextPut: 3]. "Shorter but tricky" packet := ByteArray readHexFrom: '4F457403', (peerId printStringBase: 16 length: 4 padded: true), '000003'. socket sendUDPData: packet toHost: server port: 30000. UIManager default inform: 'Disconnected from Minetest server.'. ]. socket closeAndDestroy. ----- http://drgeo.eu -- Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html