help-smalltalk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Help on sending a UDP Packet


From: address@hidden
Subject: Re: Help on sending a UDP Packet
Date: Thu, 7 Jan 2021 16:18:46 +0100 (CET)

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 gary.highberger@gmail.com:

> 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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]