LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices

Reply
 
LinkBack Search this Thread
Old 02-04-2014, 09:25 AM   #1
XXLRay
Member
 
Registered: May 2010
Posts: 115

Rep: Reputation: 16
Communication over local UNIX sockets


I have a system in which I have to isolate certain processes from each other. The decision is to use Linux Containers (lxc). (If you don't know what a container is simply assume it's a light weight virtual machine.)

Some of these need to communicate with each other. As I can share directories by mounting them from the host system the idea was to use local sockets similar to /var/lib/mysql/mysql.sock instead of network connections.

I found lots of tutorials on how to set up network sockets in C but is there any way to set up a simple hello world local socket example in shell script?
 
Old 02-04-2014, 05:46 PM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 26,516
Blog Entries: 51

Rep: Reputation: 2598Reputation: 2598Reputation: 2598Reputation: 2598Reputation: 2598Reputation: 2598Reputation: 2598Reputation: 2598Reputation: 2598Reputation: 2598Reputation: 2598
For UNIX sockets see 'man socat': UNIX-LISTEN?
 
Old 02-05-2014, 01:51 AM   #3
XXLRay
Member
 
Registered: May 2010
Posts: 115

Original Poster
Rep: Reputation: 16
Thanks for pointing me to that one,

It seems as if I can send data to a socket file by:
Code:
echo 'Hello, World!' | socat - UNIX-SENDTO:/tmp/foo.sock
and that I can listen to it by:
Code:
socat - UNIX-LISTEN:/tmp/foo.sock
but how to I create such a UNIX domain stream socket? I get only "No such file or directory" if I try it without creating one.

I was able to create and listen to a socket by:
Code:
nc -Ul /tmp/foo.sock
and I can send data to it by:
Code:
echo 'Hello, World!' | socat - UNIX-CONNECT:/tmp/foo.sock
Unfortunately the socket is closed afterwards.

I tried to only create a socket by:
Code:
nc -U /tmp/foo.sock
and to listen to it by:
Code:
socat - UNIX-LISTEN:/tmp/foo.sock
But I only get "socat[15155] E bind(3, {AF=1 "/tmp/foo.sock"}, 15): Address already in use"

Isn't there a way to create a UNIX domain socket, listen to it permanently and send data to it?
 
Old 02-07-2014, 01:02 AM   #4
unSpawn
Moderator
 
Registered: May 2001
Posts: 26,516
Blog Entries: 51

Rep: Reputation: 2598Reputation: 2598Reputation: 2598Reputation: 2598Reputation: 2598Reputation: 2598Reputation: 2598Reputation: 2598Reputation: 2598Reputation: 2598Reputation: 2598
If you want netcat to listen continuously then add "-k"?
 
1 members found this post helpful.
Old 02-07-2014, 01:27 AM   #5
XXLRay
Member
 
Registered: May 2010
Posts: 115

Original Poster
Rep: Reputation: 16
I totally overlooked that. Thanks a lot -> solved!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to get the RSSI and SNR values for Wifi communication using TCP sockets? princehektor Linux - Networking 0 07-06-2012 07:57 PM
UNIX Domain Sockets tolekutma Programming 5 03-20-2011 04:11 AM
Communication using RAW sockets ThirtySixBelow Linux - Software 2 12-23-2009 04:00 PM
Program to forward tcp sockets to unix domain sockets mikepol Linux - Networking 0 09-27-2007 09:49 AM
Issues with UNIX Local Sockets permission ghoughto Programming 2 12-13-2004 06:38 PM


All times are GMT -5. The time now is 11:46 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration