lua-enet

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
EliterScripts
Citizen
Posts: 85
Joined: Sat Oct 25, 2014 7:07 pm

lua-enet

Post by EliterScripts »

I made a host, with lua-enet, by doing

Code: Select all

enet.host_create("localhost:65927")
and having a client connect to that, and the client and server never connect!

See, I am using a computer that is connected to my home wifi (this is the server); and a computer on my desk, connected to the same network(this is the client), and there is no internet interaction with the lua-enet stuff. So, why is it not connecting? The server is running Windows 8 (client version), and the client is running Windows 7 (client version). And this is AAALLLLLL connected to the same network. Both computers have LOVE2D installed.
User avatar
Kingdaro
Party member
Posts: 395
Joined: Sun Jul 18, 2010 3:08 am

Re: lua-enet

Post by Kingdaro »

Try connecting to 192.168.0.1, or whatever it says for the server computer when typing in "ipconfig" in the command prompt. localhost and 127.0.0.1 are both for your computer and your computer only, if I remember correctly.

Image
EliterScripts
Citizen
Posts: 85
Joined: Sat Oct 25, 2014 7:07 pm

Re: lua-enet

Post by EliterScripts »

also, I do not buy a static IP from my ISP, and is this compatable with both internal network IP's and external IP's(external, as in, what reaches the internet)?
bobbyjones
Party member
Posts: 730
Joined: Sat Apr 26, 2014 7:46 pm

Re: lua-enet

Post by bobbyjones »

You could just use your internal IP. Just try it out. It usually work. If you want two PC from different networks to connect use your external IP and set up port forwarding.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: lua-enet

Post by bartbes »

EliterScripts wrote:I made a host, with lua-enet, by doing

Code: Select all

enet.host_create("localhost:65927")
Specifying localhost in the host field, if enet is anything like other network backends, means to restrict yourself to connections from localhost only. You probably want 0.0.0.0 instead, indicating everyone can connect. (Or more specifically, to listen on all interfaces.)
EliterScripts
Citizen
Posts: 85
Joined: Sat Oct 25, 2014 7:07 pm

Re: lua-enet

Post by EliterScripts »

Here's my client version (with the encryption password editted.)

Code: Select all

-- client.lua
Status, ErrCode = pcall( function ()
require "enet"
require "aeslua"
local host = enet.host_create()
local server = host:connect("0.0.0.0:65927")
while true do
  local event = host:service(100)
  while event do
    if event.type == "receive" then
      print("Got message: ", tostring(aeslua.decrypt("secretpassword",tostring(event.data))), tostring(event.peer))
      --event.peer:send( aeslua.encrypt("secretpassword","%$>CMD notepad") )
		io.write(">")
		a = io.read()
		a = "%$>" .. a
		pcall(function () a=aeslua.encrypt("secretpassword",a) end)
		event.peer:send(a)
	elseif event.type == "connect" then
      print(tostring(event.peer) .. " connected.")
      event.peer:send( "ping" )
    elseif event.type == "disconnect" then
      print(tostring(event.peer) .. " disconnected.")
	end
    event = host:service()
  end
end end)
print(Status, ErrCode)
while true do
end
And here's my server version (with the encryption code in another file, but it it's the same.) (I also figured, if I had destroyed the host, and set it back to local host, it might follow my dynamic internal IP, and dynamic external IP(don't know much about networks, just preparing my script for IP changes))

Code: Select all

-- server.lua
require "enet"
require "aeslua"
require "Settings"
local host = enet.host_create("0.0.0.0:65927")
Last_Disconnect = 0
PEER = false
while true do
Key = "%$>"
key = Key
	local event = host:service(Settings.timeout)
	while event do
		if event.type == "receive" then
			PEER = true
			Last_Disconnect = love.timer.getTime()
			local Dstat, Derror = pcall(function () Data = aeslua.decrypt(Settings.encryption_code,tostring(event.data)) end)
			if Dstat == false then print(tostring(event.peer).." sent invalid packet.") event.peer:send("INCORRECT ENCRYPTION CODE")
			else
			print("Got message: ", Data, tostring(event.peer))
				if string.sub(Data,1,#Key)==Key then
				Data = tostring(string.sub(Data,#key+1,#Data))
					print(string.sub(Data,1, 4))
					if string.sub(Data,1, 4)=="LUA " then
						local Command = string.sub(Data,5,#Data)
						local status, ErrorCode = pcall(loadstring(Command))
						local Command = nil
						event.peer:send( aeslua.encrypt(Settings.encryption_code,"STATUS: "..tostring(status)..";\n Error: "..(tostring(ErrorCode) or "(no error)").."\n" ))
						status = nil
						ErrorCode = nil
					elseif string.sub(Data,1, 4)=="CMD " then
						local Command = string.sub(Data,5,#Data)
						local status, ErrorCode = pcall(function () Args = os.execute(Command) end)
						local Command = nil
						event.peer:send( aeslua.encrypt(Settings.encryption_code,"STATUS: "..tostring(status)..";\n Error: "..(tostring(ErrorCode) or "(no error)")..";\n RETURNED: "..(Args or "(nothing returned)").."\n"))
						Args = nil
						status = nil
						ErrorCode = nil
						Command = nil
					else
					event.peer:send( aeslua.encrypt(Settings.encryption_code,"ERROR EXECUTING COMMAND") )
					end
				else
				event.peer:send( aeslua.encrypt(Settings.encryption_code,"ERROR INITIALIZING COMMAND") )
				end
			end
		elseif event.type == "connect" then
	print(tostring(event.peer) .. " connected.")
		PEER = true
		Last_Disconnect = love.timer.getTime()
		elseif event.type == "disconnect" then
		print(tostring(event.peer) .. " disconnected.")
		PEER = false
		Last_Disconnect = love.timer.getTime()
		end
	event = host:service()
	end
	if (love.timer.getTime()-Last_Disconnect)>=Settings.reconnect_frequency and PEER==false then
		print("reconnecting IP (since running on a dynamic IP)")
		Last_Disconnect = love.timer.getTime()
		host:destroy()
		host = enet.host_create("localhost:65927")
	end
end-
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: lua-enet

Post by bartbes »

EliterScripts wrote:

Code: Select all

-- client.lua
local server = host:connect("0.0.0.0:65927")
You need to connect to the ip address of the server.
EliterScripts
Citizen
Posts: 85
Joined: Sat Oct 25, 2014 7:07 pm

Re: lua-enet

Post by EliterScripts »

isn't 0.0.0.0:65927 the server's IP?

also, barbles, can we meet on the IRC?
EliterScripts
Citizen
Posts: 85
Joined: Sat Oct 25, 2014 7:07 pm

Re: lua-enet

Post by EliterScripts »

This might be a problem
Attachments
Problem.png
Problem.png (31.01 KiB) Viewed 3067 times
User avatar
T-Bone
Inner party member
Posts: 1492
Joined: Thu Jun 09, 2011 9:03 am

Re: lua-enet

Post by T-Bone »

EliterScripts wrote:isn't 0.0.0.0:65927 the server's IP??
0.0.0.0 doesn't sound like an IP address to a server. It's probably something like 192.168.0.X if you're on the same network (or just "localhost" if it's on the same computer).
Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests