File: abstract-ns-server.lua

package info (click to toggle)
lua-posix 36.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,720 kB
  • sloc: ansic: 5,462; makefile: 21; sh: 6
file content (20 lines) | stat: -rw-r--r-- 532 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#!/usr/bin/env lua

local M = require 'posix.sys.socket'


-- Create an AF_UNIX datagram socket
local s, errmsg = M.socket(M.AF_UNIX, M.SOCK_DGRAM, 0)
assert(s ~ = nil, errmsg)

-- Bind to the abtract AF_UNIX name 'mysocket'
local rc, errmsg = M.bind(s, {family=M.AF_UNIX, path='\0mysocket'})
assert(rc =  = 0, errmsg)

-- Receive datagrams on the socket and print out the contents
local dgram
while true do
   dgram, errmsg = M.recv(s, 1024)
   assert(dgram ~ = nil, errmsg)
   print('Got packet: [' .. tostring(dgram) .. ']')
end