mirror of
https://github.com/nim-lang/Nim.git
synced 2026-04-19 05:50:30 +00:00
net.nim: add support for Unix sockets
This commit is contained in:
6
examples/unix_socket/client.nim
Normal file
6
examples/unix_socket/client.nim
Normal file
@@ -0,0 +1,6 @@
|
||||
import net
|
||||
|
||||
let sock = newSocket(AF_UNIX, SOCK_STREAM, IPPROTO_IP)
|
||||
|
||||
sock.connectUnix("sock")
|
||||
sock.send("hello\n")
|
||||
14
examples/unix_socket/server.nim
Normal file
14
examples/unix_socket/server.nim
Normal file
@@ -0,0 +1,14 @@
|
||||
import net
|
||||
|
||||
let sock = newSocket(AF_UNIX, SOCK_STREAM, IPPROTO_IP)
|
||||
sock.bindUnix("sock")
|
||||
sock.listen()
|
||||
|
||||
while true:
|
||||
var client = new(Socket)
|
||||
sock.accept(client)
|
||||
var output = ""
|
||||
output.setLen 32
|
||||
client.readLine(output)
|
||||
echo "got ", output
|
||||
client.close()
|
||||
Reference in New Issue
Block a user