Skip to content

Instantly share code, notes, and snippets.

@CapsAdmin
Created April 23, 2014 17:05
Show Gist options
  • Select an option

  • Save CapsAdmin/11223743 to your computer and use it in GitHub Desktop.

Select an option

Save CapsAdmin/11223743 to your computer and use it in GitHub Desktop.
local server = luasocket.TCPServer()
server:Bind("localhost", 1000)
local client = luasocket.TCPClient()
client:Connect("localhost", 1000)
client:Send("hello\n")
client:Send("hello\n")
client:Send("hello\n")
client:Send("hello\n")
--[[
server_tcp[127.0.0.1][1000] - client_tcp[127.0.0.1][22874] connected
client_tcp[127.0.0.1][1000] - connected to 127.0.0.1:1000
client_tcp[127.0.0.1][1000] - sucessfully sent "hello\n"
server_tcp[127.0.0.1][1000] - received hello from client_tcp[127.0.0.1][22874]
client_tcp[127.0.0.1][1000] - sucessfully sent "hello\n"
server_tcp[127.0.0.1][1000] - received hello from client_tcp[127.0.0.1][22874]
client_tcp[127.0.0.1][1000] - sucessfully sent "hello\n"
server_tcp[127.0.0.1][1000] - received hello from client_tcp[127.0.0.1][22874]
client_tcp[127.0.0.1][1000] - sucessfully sent "hello\n"
server_tcp[127.0.0.1][1000] - received hello from client_tcp[127.0.0.1][22874]
server_tcp[127.0.0.1][1000] - client_tcp[127.0.0.1][22874] wants to close
]]
--[[
server functions:
server:Bind(ip, port)
table server:GetClients()
sevrer:Remove()
server:GetIp()
server:GetPort()
server:IsValid()
server callbacks:
server.OnClientConnect(client)
server.OnClientClose(client)
server.OnClientError(client)
server.OnReceive(line, client)
server.OnError(err)
client functions:
client:Connect(ip, port)
client:Send()
client:IsConnected()
client:IsSending()
client:Remove()
client:GetIp()
client:GetPort()
client:IsValid()
client callbacks:
client.OnConnect(ip, port)
client.OnSend(data)
client.OnClose()
client.OnReceive(data)
client.OnError()
]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment