SocketConnection
Inherits from: Object
A bidirectional connection over a Unix domain socket.
SocketConnection objects are returned by UnixSocketServer>>accept and UnixSocketClient>>connectTo:. They support both raw byte I/O and line-based protocols (ideal for JSON-RPC).
Example
"Line-based JSON-RPC protocol"
| conn <SocketConnection> response <String> |
conn := UnixSocketClient connectTo: '/tmp/rpc.sock'.
conn sendLine: '{"jsonrpc":"2.0","method":"ping","id":1}'.
response := conn receiveLine.
conn close
Example
"Raw send/receive"
| conn <SocketConnection> data <String> |
conn := UnixSocketClient connectTo: '/tmp/app.sock'.
conn send: 'HELLO'.
data := conn receive.
conn close
Instance Methods
primitives
primClose
primIsClosed
primReceive
primReceiveLine
primReceiveMax:
primSend:
primSendLine:
uncategorized
close
Close the connection.
Example
conn close.
conn isClosed "=> true"
isClosed
True if the connection has been closed.
receive
Read up to 4096 bytes from the connection. Blocks until data is available.
Example
| data <String> |
data := conn receive
receive:
Read up to maxBytes bytes from the connection.
Example
| data <String> |
data := conn receive: 1024
receiveLine
Read one newline-delimited line. The trailing newline is stripped. Blocks until a full line is available.
Example
| line <String> |
line := conn receiveLine
send:
Send raw string data over the connection.
Example
conn send: 'hello world'
sendLine:
Send a string followed by a newline. Useful for line-delimited protocols like JSON-RPC.
Example
conn sendLine: '{"method":"test"}'