3 Replies - 4533 Views - Last Post: 22 December 2012 - 05:51 PM Rate Topic: -----

#1 cygorx  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 20-December 12

How would I go about programming this?

Posted 20 December 2012 - 02:36 PM

I'm a newb to LuaSocket, and I'm trying to program a cross-operating system terminal program that's basically just an IRC.
I'm expecting to have to set up a webserver that handles the TCP packets and sends them back to the clients, yet the LuaSocket documentation is so vague it's quite hard to get results.

...besides that, I have this extremely erroneous Lua/Ubuntu set up in which I can't even begin to get require("socket") to work.
If any Ubuntu users out there could help me with that part:


REDACTED@REDACTED-VPCCW21FX:~$ lua ~/Lua/main.lua
lua: /home/REDACTED/Lua/main.lua:2: module 'socket' not found:
no field package.preload['socket']
no file '/usr/local/share/lua/5.2/socket.lua'
no file '/usr/local/share/lua/5.2/socket/init.lua'
no file '/usr/local/lib/lua/5.2/socket.lua'
no file '/usr/local/lib/lua/5.2/socket/init.lua'
no file './socket.lua'
no file '/usr/local/lib/lua/5.2/socket.so'
no file '/usr/local/lib/lua/5.2/loadall.so'
no file './socket.so'
stack traceback:
[C]: in function 'require'
/home/REDACTED/Lua/main.lua:2: in main chunk
[C]: in ?
REDACTED@REDACTED-VPCCW21FX:~$

The contents of main.lua:

-- load namespace
local socket = require("socket")
-- create a TCP socket and bind it to the local host, at any port
local server = assert(socket.bind("*", 0))
-- find out which port the OS chose for us
local ip, port = server:getsockname()
-- print a message informing what's up
print("Please telnet to localhost on port " .. port)
print("After connecting, you have 10s to enter a line to be echoed")
-- loop forever waiting for clients
while 1 do
-- wait for a connection from any client
local client = server:accept()
-- make sure we don't block waiting for this client's line
client:settimeout(10)
-- receive the line
local line, err = client:receive()
-- if there was no error, send it back to the client
if not err then client:send(line .. "\n") end
-- done with client, close the object
client:close()
end

(this is from LuaSocket's documentation).

I have a TeamViewer, if anyone can help me with this that'd be great.
Both /usr/local/share/lua/5.2 and /usr/local/lib/lua/5.2 exist, but do not contain anything.
Yes, I have both lualib5.2-socket2 and luasocket installed.
So obviously the directory is empty and/or incorrect, but I have no idea how to fix it.

YET, keep the focal question mind: how would I go about programming the "IRC" I'd like?

Is This A Good Question/Topic? 0
  • +

Replies To: How would I go about programming this?

#2 ishkabible  Icon User is offline

  • spelling expret
  • member icon




Reputation: 1623
  • View blog
  • Posts: 5,709
  • Joined: 03-August 09

Re: How would I go about programming this?

Posted 21 December 2012 - 04:07 PM

I thin that Lua socket is only for 5.1 but it looks like you have the latest version, 5.2.

that said I wrote an IRC bot in Lua a while back.

I connected like so
sock, err = socket.connect("irc.somehost.net", 6667) --the last argument is the port number



it returns the socket, and an error if there is one. you can also use an IP address rather than the host name for the first argument. this is a read-write socket as well.

to send data I used the 'send' method of the socket

sock:send("PRIVMSG "..to.." :"..msg.."\r\n")


to read I used the 'receive' method of the socket

recv = sock:receive()


in the documentation you can see that 'receive' accepts different arguments. by default it reads a line, which was perfect for IRC. you can request that it read many different items.
Was This Post Helpful? 0
  • +
  • -

#3 cygorx  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 20-December 12

Re: How would I go about programming this?

Posted 22 December 2012 - 08:10 AM

Thanks much ishkabible, but how would you parse the send()? Would you do so on the irc server's host or would you do it via client?
Was This Post Helpful? 0
  • +
  • -

#4 ishkabible  Icon User is offline

  • spelling expret
  • member icon




Reputation: 1623
  • View blog
  • Posts: 5,709
  • Joined: 03-August 09

Re: How would I go about programming this?

Posted 22 December 2012 - 05:51 PM

what do you mean? what I'm sending there is just a string which the server parses and sends, slightly modified, to everyone subscribing to 'to' weather that be a channel or a specific person.

here is the documentation I used to figure out the IRC protocol.

This post has been edited by ishkabible: 22 December 2012 - 05:54 PM

Was This Post Helpful? 1
  • +
  • -

Page 1 of 1