A local interprocess communication clientsocket.
Available on UNIX-like operating systems, and Windows 10 Build 17063 or above. Not all features are supported on Windows.
NOTE To use UNIXSocket, you must explicitly import it with require "socket"
Example usage:
require "socket"
sock = UNIXSocket.new("/tmp/myapp.sock")
sock.puts "message"
response = sock.gets
sock.close Connects a named UNIX socket, bound to a filesystem pathname.
Creates an UNIXSocket from an existing system file descriptor or socket handle.
Opens an UNIX socket to a filesystem pathname, yields it to the block, then eventually closes the socket when the block returns.
Returns a pair of unnamed UNIX sockets.
Creates a pair of unnamed UNIX sockets (see .pair) and yields them to the block.
Receives a text message from the previously bound address.
Socket
Socket
Socket
Crystal::System::Socket
Crystal::System::Socket
IO::Buffered
IO
IO
Reference
Reference
Reference
Object
Object
Object
Connects a named UNIX socket, bound to a filesystem pathname.
Creates an UNIXSocket from an existing system file descriptor or socket handle.
This adopts the system socket 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.
Opens an UNIX socket to a filesystem pathname, yields it to the block, then eventually closes the socket when the block returns.
Returns the value of the block.
Returns a pair of unnamed UNIX sockets.
require "socket" left, right = UNIXSocket.pair spawn do # echo server message = right.gets right.puts message end left.puts "message" left.gets # => "message"
Creates a pair of unnamed UNIX sockets (see .pair) and yields them to the block. Eventually closes both sockets when the block returns.
Returns the value of the block.
Receives a text message from the previously bound address.
require "socket"
server = Socket.udp(Socket::Family::INET)
server.bind("localhost", 1234)
message, client_addr = server.receive
© 2012–2026 Manas Technology Solutions.
Licensed under the Apache License, Version 2.0.
https://crystal-lang.org/api/1.19.0/UNIXSocket.html