unix-socket

How can I delete a UNIX Domain Socket file when I exit my application?

烈酒焚心 提交于 2019-12-08 15:55:37
问题 I have a server application that creates a UNIX Domain Socket in a specific path with a name and bind() s to it. I need to delete the socket only when I close/stop the application intentionally, from within the the application code; otherwise it needs to be open. How do I do this? Thanks! Edit: Consider that I start and run my application from inside a terminal. 回答1: You're making this harder than it needs to be. Put the unlink() right before the bind() . That's how everybody else does it.

a LocalSocket (Unix domain) client-server data flow issue for MediaRecorder in Android (Java)

拥有回忆 提交于 2019-12-06 12:46:10
What I don't get is data flow among the Unix Domain Sockets . I understand Unix Domain Socket data flow is LocalSocket client .connect() --> LocalServerSocket server .accept() The client sends data to the server, straight enough that I understand. However, for Streaming video/audio from MediaRecorder of Android, after a lot of research, I've seen every example to use a LocalSocket instead of a file for MediaRecorder is in principle as below: https://static.foxdogstudios.com/static/presentations/keeping-it-real-time.html#/9 LocalServerSocket server = new LocalServerSocket("some name"); receiver

How can I map a local unix socket to an inet socket?

牧云@^-^@ 提交于 2019-12-06 10:20:07
问题 I'm curious if it is possible to map a UNIX socket on to an INET socket. The situation is simply that I'd like to connect to a MySQL server. Unfortunately it has INET sockets disabled and therefore I can only connect with UNIX sockets. The tools I'm using/writing have to connect on an INET socket, so I'm trying to see if I can map one on to the other. It took a fair amount of searching but I did find socat, which purportedly does what I'm looking for. I was wondering if anyone has any

C unix domain sockets, recvfrom() doesn't set struct sockaddr* src_addr

末鹿安然 提交于 2019-12-06 00:59:41
问题 I'm writing an application that listens for UDP packets over a unix domain socket. Consider the following code block. int sockfd; struct sockaddr_un servaddr; sockfd = socket(AF_LOCAL, SOCK_DGRAM, 0); if(sockfd < 0) { perror("socket() failed"); } unlink(port); bzero(&servaddr, sizeof(servaddr)); servaddr.sun_family = AF_LOCAL; strcpy(servaddr.sun_path, port); if(bind(sockfd, (struct sockaddr *)&servaddr, sizeof(servaddr)) < 0) { perror("bind() failed"); close(sockfd); } int n; struct sockaddr

Unix C socket server not accepting connections

不羁岁月 提交于 2019-12-06 00:03:27
Here's the deal, I'm writing a simple tcp socket server in C (with unix system calls) that I'm not able to get to accept connections. From what I can tell, I get through the server initialization just fine, but when I try to connect to the port that I print out (see code below) it refuses as if nothing is there. More to the point, when I netstat that port isn't even in use. I'm not throwing any errors with my current set up, I'm all dried up for ideas. int main(){ int sock_fd; int conn_fd; struct sockaddr_in serv_addr; struct sockaddr_in cli_addr; socklen_t* serlen; socklen_t* clilen; clilen =

How to view and edit the ephemeral port range on Linux?

℡╲_俬逩灬. 提交于 2019-12-06 00:00:42
问题 In my Linux system ephemeral port range is showing different ranges as follows $ cat /proc/sys/net/ipv4/ip_local_port_range 32768 61000  cat /etc/sysctl.conf | grep net.ipv4.ip_local_port_range net.ipv4.ip_local_port_range = 9000 65500 Which will be the effective ephemeral port range in my system? 回答1: Following command will list the ephemeral port range in Linux system sysctl -A | grep ip_local_port_range If we don't want to reboot, after editing /etc/sysctl.conf file if we execute

Unix Sockets : AF_LOCAL vs AF_INET

霸气de小男生 提交于 2019-12-05 19:28:11
问题 I'm just starting with socket programming in UNIX and I was reading the man pages for the socket system call. I'm a bit confused about the AF_LOCAL argument and when it is used. The manual just says local communication. Wouldn't an AF_INET format also work for local communication? 回答1: AF_LOCAL uses UNIX domain sockets which are local to the filesystem and can be used for internal communications. AF_INET is an IP socket. AF_LOCAL will not incur some performance penalties related to sending

Identify program that connects to a Unix Domain Socket

若如初见. 提交于 2019-12-05 15:57:35
问题 I have a program that is listening to a Unix Domain Socket. When a client connects to the socket I'd like to find out which program connected and then decide if I allow the connection or not (based on the user/group settings). Is this possible under Linux, and if so, how? 回答1: Yes, this is possible on Linux, but it won't be very portable. It's achieved using what is called "ancillary data" with sendmsg / recvmsg . Use SO_PASSCRED with setsockopt Use SCM_CREDENTIALS and the struct ucred

Unix socket connection to MySql with Java to avoid JDBC's TCP/IP overhead?

試著忘記壹切 提交于 2019-12-05 07:59:45
Is it possible to make a Unix socket connection to MySql with Java to avoid JDBC's TCP/IP overhead? Does anyone know a library (or a few libraries, perhaps) that makes this possible? Also the mySQL JDBC driver has been polished over a long period and has several optimization tweaks , like caching of metadata. I would be surprised that the JDBC developers would have left a lot of TCP/IP overhead in the driver. Going over JNI to the C based implementation would probably cost more in jumping to native code than can be gained from reduced TCP/IP overhead. If you really want to cut out the TCP/IP

Node.js: Send GET request via unix socket

落花浮王杯 提交于 2019-12-05 04:28:28
I am new to the node.js . I am trying to setup the client server connection using unix socket, where my client request would be in node.js and server running in the background would be in go. Client side Code: var request = require('request'); request('http://unix:/tmp/static0.sock:/volumes/list', function (error, response, body) { if (!error && response.statusCode == 200) { console.log(body) } else { console.log("In else part of the receiver" + response.statusCode + body) } } }) When I try to communicate with the server written in go it is shows the HTTP error: 400 Bad Request: malformed Host