Personal computing discussed

Moderators: renee, SecretSquirrel, notfred

 
Flatland_Spider
Graphmaster Gerbil
Topic Author
Posts: 1324
Joined: Mon Sep 13, 2004 8:33 pm

Playing with sockets

Fri Feb 07, 2014 7:38 pm

I'm trying to play around with Unix sockets. I'm trying to create a socket that will deliver a little text string payload, "Hello world.", each time a connection is made, and I'm going to write a little python program that will connect to the socket.

I've been working with ncat, but it's not working particularly well.

Term1:
$ echo "Hello world." | ncat -lU ./test.sock -k

Term2:
$ ncat -U ./test.sock
"Hello World"
<ctrl+d>
$ ncat -U ./test.sock
<ctrl+d>
$


It's also not cleaning up the socket, but that fixed with a script.

Any ideas? I could switch to socat, but I'm not familiar with that program.
 
way2strong
Gerbil
Posts: 51
Joined: Fri Jun 27, 2008 7:07 am

Re: Playing with sockets

Sat Feb 08, 2014 4:15 am

This is out of my depth so don't expect much more from me, but this will print the message every time a connection is made.

ncat -lU ./test.socket -c "echo Hello World." -k
 
Flatland_Spider
Graphmaster Gerbil
Topic Author
Posts: 1324
Joined: Mon Sep 13, 2004 8:33 pm

Re: Playing with sockets

Sat Feb 08, 2014 10:39 am

That did it. Thanks!

Now I just need to get it to send an EOF so the connection will close.
 
notfred
Maximum Gerbil
Posts: 4610
Joined: Tue Aug 10, 2004 10:10 am
Location: Ottawa, Canada

Re: Playing with sockets

Sat Feb 08, 2014 10:47 am

Haven't used ncat, if you are happy programming in C there are plenty of socket tutorials around that do exactly what you are looking for. C is the real language of Unix and sockets.
 
Flatland_Spider
Graphmaster Gerbil
Topic Author
Posts: 1324
Joined: Mon Sep 13, 2004 8:33 pm

Re: Playing with sockets

Sat Feb 08, 2014 11:27 am

I figured it out. --recv-only was missing on the receiving side.

Term 1:
ncat -lU ./test.sock -c "echo Hello World." -k

Term 2:
$ncat --recv-only -U ./test.sock
Hello World.
$


Alternately,

With that working, I'm moving on to seeing if I can get python to connect to it.

@notfred
That did cross my mind. I just wanted to get a quick prototype socket up, so I could move on to writing the python program. I'm going to try writing a C program that will create a socket one of these days, but today is not that day.

The socket I want to connect to already exists (It's the Docker socket), and as soon as python is connecting to this prototype socket, I'm going to switch over to the real socket.

Who is online

Users browsing this forum: No registered users and 8 guests
GZIP: On