[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Charachter based input/socket handling
- From: Paco Willers <paco.willers@...>
- Date: Sun, 15 Jul 2012 05:42:47 +0200
I couldn't find this in the mailing list archives, nor anywhere else, so I'm asking this here though. :-) I searched anywhere. Not finding it makes me feel like:
- either nobody asks because the solution is simple
- my approach is faulty
- or nobody ever wanted to know :-)
What I need is a character based input without an end of line symbol. Like in BASIC: INKEY$.
Anyway... I am writing a multiple user telnet (game) server in Lua using LuaSocket and/or Copas libraries.
By the way, I said "telnet game", but I didn't mean the telnet protocol. Telnet is just an example of a client application. I mean raw IP traffic. The client uses "Telnet" or "PuTTY" .
So I encounter two challenges:
1.) On the client side passwords must be discretely displayed as asterisks.
2.) The game simulates time consuming processes, so an animated busy - \ | / cursor or a 0%-100% process bar should be run without blocking other clients (coroutines).
I could have a completely wrong understanding of the concept, but the LuaSocket and Copas libraries only have line-based entries:
1.) The client types it's password which is directly echoed to the client's screen, and is sent to the server after pressing <enter>. So no asterisks can be echoed.
2.) A socket's coroutine can of course display busy cursors or progress bars, but they block other client's coroutines while counting.
The solution should be: character-orientent traffic instead of line-oriented traffic. In case of passwords, the server should echo an asterisk directly after typing a character on the client side. The server should also be able to yield to another client (coroutine) to be able to display progress bars (characters) without blocking.
In my opinion, character based communication is the solution (yield or read one character and send one), instead of line-based, but how to accomplish that? The Copas manual says that copas.read() has arguments, but it refers to the LuaSocket manual. It says: line/all/number. Line is standard. That sounds OK, because io.read() has something similar. So I tried it with a number like 1. It works! Copas.read() really processes the input as separated characters. The LuaSocket equivalent also does, and so does io.read(). But... the real processing of these characters begins after the function reaches end of line (or <enter>).
How can I process character input from copas.read(), socket.read() or io.read() or whatever without first having to reach an end of line character? Or is my approach completely wrong?
Have a nice day,