Skip to content

Instantly share code, notes, and snippets.

@Loopshape
Forked from cwilhit/WindowsUnixSocket.cpp
Created February 21, 2018 04:55
Show Gist options
  • Save Loopshape/d7b86b55130fdf68418494ac96c0f7f7 to your computer and use it in GitHub Desktop.
Save Loopshape/d7b86b55130fdf68418494ac96c0f7f7 to your computer and use it in GitHub Desktop.
// Create a server AF_UNIX socket
#define SERVER_ADDRESS “c:\unix\server.sock”
SOCKADDR_UN ServerAddress = {0};
Server = socket(AF_UNIX, SOCK_STREAM, 0);
// Bind the socket to a path.
ServerAddress.sun_family = AF_UNIX;
strcpy(ServerAddress.sun_path, SERVER_ADDRESS);
bind(Server, &ServerAddress, sizeof(ServerAddress));
// Accept a connection.
listen(Server, 5);
Accepted = accept(Server, ….);
// Send and receive data on the accepted socket.
// Shutdown and close the connection.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment