Open Client or Server Socket

tcp_client

ok = socko:open(peername, peerport, [ms], [intf])

Attempt to connect to a peer's listening socket.

Parameter Type Description
peername string Host name or IP address to connect to
peerport integer The TCP port to connect to
ms integer Timeout
intf string Name of interface to force
Returns Type Description
ok boolean True if connected

tcp_server

ok = socko:open(allow, port, [intf])

Open a listening TCP socket.

Parameter Type Description
allow string List of addresses (or wildcards) to allow connection
port integer The TCP port to listen on
intf string Name of interface to force

Once you have the socket listening, use socket.select to check for receive activity on the socket, and then use socko﹕accept to create the specific connection socket.

udp

ok = socko:open(port)

Opens a UDP port with the local port - for sending and/or receiving UDP packets.

Parameter Type Description
port integer The TCP port to listen on

Common

intf Description
ppp Modem/Cellular/PPP
mod* Modem/Cellular/PPP, e.g. 'modem'
et* Ethernet, e.g. 'eth'
lo* Loopback interface, e.g. 'loop'

See:: socket.new

Server Example

Rough server example:

svro = socket.new('tcp_server') -- Server listen
svro.open('', 12345) -- any device on port 12345

while tools.run()
do
  local rxt
  local count
  rxt = {svro}
  count, rxt = socket.select(1000, rxt)
  if count > 0
  then
    local pipeo = svro:accept()
    if pipeo
    then
      -- do some connection stuff
      pipeo:send("High and goodbye") -- we are blocking other sockets though!
      pipeo:close()
    end
  end
end