lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


I'm looking for an ansynchronous socket ( TCP/IP and UDP ) library for lua. I've found asok.lua (http://ztact.com/software/asok.lua) but the last release of that was almost 1 year ago and was 'beta quality'. I'll try and get that running but I was curious if there are others available.

 

The goal is to allow our  users to write scripts which interact with devices on the network

  (1) without having to learn the Berkley sockets interface

  (2) ensure that their script don't block execution for too long a time

  (3) without having to understand coroutines and yield()

  (4) run on both Win32 and Linux platforms

 

Something similar to the .NET System.Net.Sockets would be ideal - each call that could block ( Connect, Send, Receive ) has both a Begin* and End* model and code might look something like

 

function ReceiveCallBack( arg, socket )

  data, err = socket:EndReceive(arg)

  if err then print( err ) end

  print( "got "..data.." back")

end

 

function SendCallback( arg, socket )

  err = socket:EndSend(arg)

  if err then print( err )

    -- read until null on stream

 else socket:BeginReceive( ReceiveCallback ) end

end

 

function ConnectCallback( arg, socket )

  err =  socket:EndConnect(arg)

  if err then print( err )

  else socket:BeginSend( "send a string", SendCallback ) end

end

 

socket, err = Socket.New()

socket.Connect( "123.123.123.123", 23, ConnectCallBack )

 

Optionally, an interface that looked something like Flash XMLSocket would also work - it's event handler based

 

function ReceiveHandler( socket, data )

  print( "got "..data.." back")

end

 

function ConnectHandler( socket )

  socket.Send("send a string" )

end

 

function ErrorHandler( err )

  print( err )

end

 

socket, err = Socket.New()

socket:_OnReceive_ = ReceiveHandler

socket:_OnError_ = ErrorHandler

socket:_OnConnect_ = ConnectHandler

socket.Connect("123.123.123.123", 23)

 

Thanks-

 

John

 

John Dunn

Senior Software Engineer

Systems Development Group

QSC Audio Products, LLC

4900 Pearl East Circle, Suite 205E

Boulder, CO 80301

303.951.3000 ext 302

john_dunn@qscaudio.com

www.qscaudio.com

 

This electronic message transmission contains information from QSC Audio Products, LLC, which may be confidential or privileged. This information is intended for the use of the individual or entity named above. If you are not the intended recipient, be aware that any disclosure, copying, distribution or use of the contents of this transmission is strictly prohibited. If you have received this electronic transmission in error, please notify us immediately via telephone.