Re: Help on sending a UDP Packet

"[email protected]" <[email protected]>
Newsgroups gmane.comp.lang.smalltalk.gnu.general
Message-ID <[email protected]>
Hi,

I'm using a simple TCP/IP and UDP service called 'daytime' here.

This is a very old service, that is useful for small tests.

Traditionally this is a "inetd" service.

On my system, it is available as an inetd service.

Note that some Linux distributions do not install that service by default,
so you may have to check the Ubuntu packages or manpages.

I see that Ubuntu has an xinetd package, check or search for 
/etc/xinetd.d/daytime 	xinetd in Ubuntu

Anyway assuming that you have a daytime UDP (dgram) and TCP (stream) running.

For the TCP case the following works for me:

PackageLoader fileInPackage: 'Sockets'.

s _ Sockets.Socket remote:(Sockets.SocketAddress createLoopbackHost) port:13.
(s upTo: Character cr) printNl.
s close.

$ gst daytime-stream.st 
"Global garbage collection... done"
Loading package Sockets
'Thu Jan  7 16:13:44 2021'
$ svcs -a daytime:stream
STATE          STIME    FMRI
online         15:42:59 svc:/network/daytime:stream

Now for the UDP case (datagram) it is more complicated.

The following kind-a-works for me:

$ cat daytime-dgram.st 
PackageLoader fileInPackage: 'Sockets'.

h _ Sockets.SocketAddress createLoopbackHost.
s _ Sockets.DatagramSocket new.
d _ Sockets.Datagram data:#'hello world' address:h port:13.
answer _ Sockets.Datagram new.
s nextPut:d.
s receive:answer.
(answer data) asString printNl.
s close.

$ gst daytime-dgram.st 
"Global garbage collection... done"
Loading package Sockets
'Thu Jan  7 16:16:32 2021
'
$ svcs daytime:dgram
STATE          STIME    FMRI
online         15:42:56 svc:/network/daytime:dgram

The TCP (stream) code is neater because it uses the upTo: Character cr,
which eats the newline.

So that's a little better than in the simple UDP example.

However basically the UDP example works for me.

It sends a garbage datagram #('hello world') which is ignored by the daytime:dgram service.
But this triggers a response which we then receive in a Datagram instance 'answer'.

Regards,
David Stes

----- Op 6 jan 2021 om 21:47 schreef Gary Highberger [email protected]:

> HI everyone,
> I just started working on 4 and 5 below. Any suggestions or links to
> references would be much appreciated. I know little of Smalltalk, but am
> coming up to speed on it. I have many years of C network programming  of
> modems, switches & routers. I'll document everything as I go along.
> 
>   1. Objective is to send a UDP packet to port 49152 on my other Linux box
>   192.168.1.114:49152
>      - AF_INET (v4)
>      - SOCK_DGRAM (connectionless)
>      - IPPROTO_UDP (user datagram protocol)
>      - Any egress port and IP address (no bind)
>   2. Sockets documentation is not in gnu-smalltalk-doc. It's online at Sockets
>   Documentation
>   <https://www.gnu.org/software/smalltalk/manual-libs/gst-libs.html#Sockets-package>
>   3. Socket support must be added to gnu-smalltalk 3.2.5.  st>
>   PackageLoader fileInPackage: 'Sockets' .
>   4. Configure socket and send it a message
>   5. Observe message on Wireshark and at my other Linux box.
> 
> 
> Many thanks everybody,
> Gary Highberger
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.