ruby socket dgram example -
i'm trying use unix sockets , sock_dgram in ruby, having hard time figuring out how it. far, i've been trying things this:
sock_path = 'test.socket' s1 = socket.new(socket::af_unix, socket::sock_dgram, 0) s1.bind(socket.pack_sockaddr_un(sock_path)) s2 = socket.new(socket::af_unix, socket::sock_dgram, 0) s2.bind(socket.pack_sockaddr_un(sock_path)) s1.send("hello") s2.recv(5) # should equal "hello"
does have experience this?
in common case need use connect
, bind
both client , server sockets, need 2 different address binding
require 'socket' sock_path = 'test.socket' sock_path2 = 'test2.socket' s1 = socket.new(socket::af_unix, socket::sock_dgram, 0) s1.bind(socket.pack_sockaddr_un(sock_path)) s2 = socket.new(socket::af_unix, socket::sock_dgram, 0) s2.bind(socket.pack_sockaddr_un(sock_path2)) s2.connect(socket.pack_sockaddr_un(sock_path)) s1.connect(socket.pack_sockaddr_un(sock_path2)) s1.send("hello", 0) puts s2.recv(5) => hello
Comments
Post a Comment