Linux how to create socket file

Create file socket linux

You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today! Note that registered members see fewer ads, and ContentLink is completely disabled once you log in. Are you new to LinuxQuestions.org? Visit the following links:
Site Howto | Site FAQ | Sitemap | Register Now If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.

Introduction to Linux — A Hands on Guide This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter. For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author’s experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own. Click Here to receive this Complete Guide absolutely free.

i’m not so sure you can make that by hand — seems like the programm will have to
was it in /tmp
if so it might just be a link to something like
ln -sf /var/lib/mysql/mysql.sock /tmp/mysql.sock
or something like that
otherwise seems like a restart mysqladmin [-h . -u . -p. ] shutdown
mysqld_safe —user=mysql & if it’s suposed to be in tmp make sure mysql has write permission That has got to be one of the biggest problems with MySQL!

Everyone everywhere is getting this stupid can’t connect on mysql.sock and there is nothing at their site or on the Internet saying why this happens. Further, there should be a way to make a simple socket file, and you can’t find that anywhere either. From what I’ve read, the temporary file is created in the mysql directory, while KDE tries to create her own sockets, temporary ones in /tmp There are problems with pthreads, and so on, but if the MySQL development team would go after this bug, they might get a lot of disconnection errors fixed. The distribution should come with a copy of the socket file and not depend on C++ to have one compiled in without any recourse. It really is beginning to look like MySQL team did not know what it was doing with sockets, auths, and a lot more. A socket should be a simple thing and it should work, without the really stupid error message «can’t connect using socket,» of course it can’t connect dummy, but why can’t it connect? here, I created the mysql.sock file and echo’ed a null character to it. I created this in /var/run/mysql but as it turns out the file created is a pipe and not a socket, which may dismay the author of the other article a bit. Perhaps there is a mksocket command [no such luck!].

Читайте также:  Просмотр содержимого директории linux

If you found an answer, please reply. This topic was originally posted about 2.75 years ago. Has anyone
figured out in the interim how to create a «socket file»? They are
sitting here on this Linux machine I am using, eg: bash> ls -F /tmp/.X11-unix/X0
/tmp/.X11-unix/X0= bash> file /tmp/.X11-unix/X0
/tmp/.X11-unix/X0: socket I have been totally unsuccessful in finding a program or series of
programs which will create one of these puppies for me. I have an
application which takes input only from such a beast and I want to
be able to pump bits at it. And as has been pointed out in other
threads, a file socket is NOT the same thing as a file pipe. Probably I just don’t have the right jargon for it. Pardon my *X
ignorance. Just as the Unix creators thought it appropriate that
a program named «biff» would tell us that mail had arrived (because
the guy who wrote the program had a dog named Biff which barked at
the postman), we should probably JUST KNOW that something similar
exists in this case. How about a program called «cardiac-arrest»
for creating a «file socket», so named because cardiac arrest is
what can happen when you stick a real (ie steel) file into a real
(ie 120 volt) socket? (Hot side with your other hand on a pipe,
of course.) Or some such. So, can anyone answer this question now?

I even forgot that I posted this ! I kinda lost touch with Linux in a while so thanks for reminding me that this world still exists ! However, I remember that at that time I did not find any utility that could create a socket file and I ended up in reinstalling my box.
Now that you brought this back into my attention I have done a little search in the web and maybe this will help you a little: You have to write some code in order to create the socket file, but I really don’t have any idea about how the code should look like since I know nothing about programming with gcc. I really hope this will give you a clue and I’m really sorry for not being able to provide more consistent information. mysql.sock is a fifo file. It is essentially a bidirectional pipe «|» that exists as a file so that processes can talk to eachother without going to all the trouble of using network sockets. see the options for mkfifo. on my system the file is: srwxrwxrwx mysql mysql

Also note that you should double check /etc/services and make sure mysql is listed in there (default port 3306). Lots of misunderstanding here; let’s see if I can clarify. A socket file is not a regular file, it’s more like an IP address (it is also not a fifo, although those are similar). A socket file is created by the system when a program calls bind on a unix domain socket, which is a special kind of network socket that can only be internal to one computer. The system then associates this special file with the socket file descriptor that the program bound (or more specifically, the «inode» to which that file descriptor refers). From that point on, the program that created the socket has no interaction with the socket by the filename. If you move it elsewhere, create new links to it, or remove it, you may confuse other programs that are trying to talk to the program in question, but the program itself won’t see it at all. You are only changing the set of names that point at that inode (and you can connect to the listening program at that new name!). Thinking of the filename as a domain name, the inode as the ip address, and the filesystem as DNS isn’t so very far off. So considering, in this case, mysqld and it’s socket. As should be apparent (I hope) from the above, copying a socket file created by some other program to /var/run/mysql.sock isn’t going to help re-establish communication with the mysql server — you’ve just pointed the filename you want at a different inode, and it will mean that other program (if it is still alive) will be receiving the connections that should be going to mysqld; not what we want at all. What is needed is for mysqld itself to recreate the socket. So, how can we make it do that? Per http://www.pathname.com/fhs/pub/fhs-2.3.html, the /var/run filesystem is the place for run-time variable data and should be cleared out at each boot. So a restart of the computer should do it. But that’s ugly. We should be able to just restart the service (it would be even nicer if a reload would do it, but I’ve tested and it doesn’t). So ideally, the init scripts should handle this and on the version of ubuntu I’m in front of they do. Here, sudo service mysql restart

Читайте также:  Jetbrains mono font for linux

works just fine after removing /var/run/mysql.sock, and the file is recreated. If that doesn’t work, you can try running the init scripts manually with something like sudo /etc/init.d/mysqld restart If that still doesn’t work, then you need to bring it down some other way. Per http://dev.mysql.com/doc/refman/5.0/. -response.html we see that a TERM signal will safely shut down the server, so we can say to get the pid of the running server (as mysqld is not so well behaved as to provide us with a pid file, but no biggie), and then (replacing 12345 with the pid we found): Источник

Linux named sockets howto

I know that there are named sockets & named pipes (fifo) in Linux. In ls -l , they would look as below: (I have changed the filenames, for demonstration.)

Now, a named pipe can be created using mkfifo . Is there a command for creating a named socket? Last option would be to write a C program, which would call mknod function, but wanted to know, if there is already a command for that. What I have tried:
I tried to search for any options to mknod & mkfifo, but could not find one. NOTE: I am not discussing about server-client model over Ethernet/network. The named socket file will be used by 2 processes on the same system.

3 Answers 3

A Unix/Linux socket file is basically a two-way FIFO. Since sockets were originally created as a way to manage network communications, it is possible to manipulate them using the send() and recv() system calls. However, in the Unix spirit of “everything is a file”, you can also use write() and read() . You need to use socketpair() or socket() to create named sockets. A tutorial for using sockets in C can be found here: Beej’s Guide to Unix IPC: Unix Sockets. The socat command line utility is useful when you want to play around with sockets without writing a «real» program. It is similar to netcat and acts as an adapter between different networking and file interfaces.

Читайте также:  Rs 232 ethernet linux

Источник

What are .sock files and how to communicate with them

Elaborating on the 2nd bullet, I understand that .sock files are for Inter-process communication. How can I ‘communicate’ with them? Let us say a sock file is designed to respond in a specific way (For ex: it takes the input ‘time’ and prints out the current time).

I prefer higher level programming languages (python) more than C/C++ . It’d also be better if someone can point me to some application (like nc maybe?) that I can use to communicate with .sock files in a quick and dirty way?

Please supply some context so we know what you’re asking about. Where did you encounter a ‘.sock’ file?

James, the .sock file has been preprogrammed to provide a «challenge-response» algorithm. For ex: Me to .sock: «MyUserName» .sock to me: «Here is your token: a_token». I need to figure out how to communicate with the .sock in a bidirectional way

Hello and welcome on StackOverflow. In order to get your a better answer, and your answer don’t get deleted later on, you would have to read and follow some basic rules and conventions that will help everyone to communicate and help better. Please go to stackoverflow.com/help and read about the topic «What topics can I ask about here?», and «What types of questions should I avoid asking?».

2 Answers 2

Sock files are socket files they are endpoints in communication pipes.

how to create socket files:

  • let uwsgi create them when interacting with servers(e.g. nginx) sudo uwsgi —ini /path/to/ini/file/ In the ini file you need to have passed a path to where you want to add the socket file .ini files will on unix sysytems live at /etc/uwsgi/sites/*.ini
  • create socket files using a high level language try python: python -c «import socket as s; sock = s.socket(s.AF_UNIX); sock.bind(‘/tmp/test.sock’)»
  • use nc Server side have: nc -l -p 1234 Client side have: nc -l -p 1234 That way you have a open socket that can communicate. I leave this here

Here’s detailed info on working with sockets in Python

You can communicate with sockets using netcat-openbsd or socat

UPDATE: here’s an example of a socket server taken from the first link

import socket import sys import os server_address = './uds_socket' # Make sure the socket does not already exist try: os.unlink(server_address) except OSError: if os.path.exists(server_address): raise # Create a UDS socket sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) # Bind the socket to the port print >>sys.stderr, 'starting up on %s' % server_address sock.bind(server_address) # Listen for incoming connections sock.listen(1) while True: # Wait for a connection print >>sys.stderr, 'waiting for a connection' connection, client_address = sock.accept() try: print >>sys.stderr, 'connection from', client_address # Receive the data in small chunks and retransmit it while True: data = connection.recv(16) print >>sys.stderr, 'received "%s"' % data if data: print >>sys.stderr, 'sending data back to the client' connection.sendall(data.upper()) else: print >>sys.stderr, 'no more data from', client_address break finally: # Clean up the connection connection.close() 

save this into a file called sock.py and run

~/Development/temp ᐅ python sock.py starting up on ./uds_socket waiting for a connection 

then connect using socat

~/Development/temp ᐅ socat - UNIX-CONNECT:uds_socket hello HELLO 

write something — and you’ll receive the same thing but in uppercase as a reply.

Источник

Оцените статью
Adblock
detector