A local interprocess communication server socket.
Available on UNIX-like operating systems, and Windows 10 Build 17063 or above. Not all features are supported on Windows.
NOTE To use UNIXServer, you must explicitly import it with require "socket"
Example usage:
require "socket"
def handle_client(client)
message = client.gets
client.puts message
end
server = UNIXServer.new("/tmp/myapp.sock")
while client = server.accept?
spawn handle_client(client)
end Creates a named UNIX socket, listening on a filesystem pathname.
Creates a UNIXServer from an existing system file descriptor or socket handle.
Creates a new UNIX server and yields it to the block.
Accepts an incoming connection.
Closes the socket, then deletes the filesystem pathname if it exists.
Socket::Server
UNIXSocket
UNIXSocket
UNIXSocket
Socket
Socket
Socket
Crystal::System::Socket
Crystal::System::Socket
IO::Buffered
IO
IO
Reference
Reference
Reference
Object
Object
Object
Creates a named UNIX socket, listening on a filesystem pathname.
Always deletes any existing filesystem pathname first, in order to cleanup any leftover socket file.
The server is of stream type by default, but this can be changed for another type. For example datagram messages:
UNIXServer.new("/tmp/dgram.sock", Socket::Type::DGRAM) Creates a UNIXServer from an existing system file descriptor or socket handle.
This adopts fd into the IO system that will reconfigure it as per the event loop runtime requirements.
NOTE On Windows, the handle must have been created with WSA_FLAG_OVERLAPPED.
Creates a new UNIX server and yields it to the block. Eventually closes the server socket when the block returns.
Returns the value of the block.
Accepts an incoming connection.
Returns the client socket or nil if the server is closed after invoking this method.
Closes the socket, then deletes the filesystem pathname if it exists.
© 2012–2026 Manas Technology Solutions.
Licensed under the Apache License, Version 2.0.
https://crystal-lang.org/api/1.19.0/UNIXServer.html