Created
June 7, 2020 13:56
-
-
Save selvan/cedac22faca2ac2653e886aac876dde4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Server code | |
libsocket = require "socket" | |
libunix = require "socket.unix" | |
socket = assert(libunix()) | |
SOCKET="/tmp/socket" | |
assert(socket:bind(SOCKET)) | |
assert(socket:listen()) | |
conn = assert(socket:accept()) | |
while 1 do | |
data=assert(conn:receive()) | |
print("Got line: " .. data) | |
conn:send("echo: " .. data .. "\n") | |
if data == "." then conn:close() return end | |
end | |
-- Client code | |
socket = require"socket" | |
socket.unix = require"socket.unix" | |
c = assert(socket.unix()) | |
assert(c:connect("/tmp/socket")) | |
c:send("123456\n") | |
-- data=assert(c:receive()) | |
-- print("Got line: " .. data) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment