[Solved] LUBE Question

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
User avatar
ninwa
Party member
Posts: 118
Joined: Tue Oct 12, 2010 1:21 am
Location: Metro Detroit
Contact:

[Solved] LUBE Question

Post by ninwa » Wed Oct 27, 2010 4:02 am

Hello,

I'm writing a chat server/client in LOVE using LUBE and I've run into a frustrating problem. The application worked at first, but after a short while, ceased to work. I have both my client and server set to use port 11988. I decided to do a little investigating to see why it stopped working. Using Wireshark I can see that my LOVE client changed what source port it was using to connect to the server. If I change the port values in my script to this new port, it works again for awhile, but then ceases to work (with the source port changing again.) This will happen again and again.

Screenshot of problem: http://i.imgur.com/Lrw6U.png

Server Code:

Code: Select all

require "LUBE.lua"

clientData = {}

-- Server Callbacks
function onConnect(ip, port)
	clientData[ip] = {nameSet = nil,
	                  name = "Guest" .. math.random(1,2000)}
	print("Client ["..ip.."] connected, assigned name: " .. clientData[ip].name)
end

function onReceive(data, ip, port)
	print("Data recieved:"	.. data)
	-- Parse message
	delim = string.find(data,string.char(1))
	cmd   = string.sub(data,1,delim-1)
	msg  = string.sub(data,delim+1,#data)
	
	if cmd == "name" then
		print(clientData[ip].name.." changed their name to " .. msg)
		clientData[ip].name = msg
	end
	
	if cmd == "msg" then
			server:send("msg"..string.char(1)..clientData[ip].name..": "..msg)
	end
end
function onDisconnect(ip, port)
 
end

function love.load()
	server = lube.server(11988)
	server:setCallback(onReceive, onConnect, onDisconnect)
	server:setHandshake("LoveChat Handshake")
	print("LoveChat v0.1 \nby Ninwa\n\n")
end

function love.update(dt)
  server:update(dt)
end

function love.draw()

end
Client Code:

Code: Select all

require "LUBE.lua"

function love.load()
	client = lube.client()
	client:setHandshake("LoveChat Handshake")
	client:setCallback(onReceive)
	client:connect("24.192.196.87", 11988)
	
	nameEntered = false
	name = ""
	prevMsgBuffer = {}
	msgBuffer = ""
end

function onReceive(data)
 	-- Parse message
	delim = string.find(data,string.char(1))
	cmd   = string.sub(data,1,delim-1)
	msg  = string.sub(data,delim+1,#data)
	print("data recieved: " .. data)
	if cmd == "msg" then
		table.insert(prevMsgBuffer,msg)
	end
end

function love.update(dt)
	client:update(dt)
end

function love.keypressed(key,unicode)
	if not nameEntered then
		if key == "return" then
			if #name > 2 then
				client:send("name"..string.char(1)..name)
				nameEntered = true
			end
			
			return
		end
		
		if key == "backspace" then
			name = string.sub(name,1,#name-1)
			return
		end
		
		name = name .. key
		return
	end
	
	if key == "return" then
		if #name > 2 then
			client:send("msg"..string.char(1)..msgBuffer)
			msgBuffer = ""
		end
		
		return
	end
	
	if key == "backspace" then
		msg = string.sub(msgBuffer,1,#msgBuffer-1)
		return
	end
	
	msgBuffer = msgBuffer .. key
end

function love.draw()
	-- Draw user name prompt
	if not nameEntered then
		love.graphics.print("Enter your name: " .. name,20,20)
		return
	end
	
	-- Draw enter message prompt
	love.graphics.print("message: "..msgBuffer,40,20)
	
	-- Redraw messages when there's a new one
	for i=#prevMsgBuffer, 1, -1 do
		love.graphics.print(prevMsgBuffer[i],40,14*(#prevMsgBuffer-i)+50)
	end
end
Regards,
Ninwa
Last edited by ninwa on Thu Oct 28, 2010 1:21 am, edited 1 time in total.

User avatar
ninwa
Party member
Posts: 118
Joined: Tue Oct 12, 2010 1:21 am
Location: Metro Detroit
Contact:

Re: LUBE Question

Post by ninwa » Wed Oct 27, 2010 5:34 am

Confirmed that the client/server worked as it should with Boolsheet's machine as server. My router (router skills) fail.

User avatar
ninwa
Party member
Posts: 118
Joined: Tue Oct 12, 2010 1:21 am
Location: Metro Detroit
Contact:

Re: LUBE Question

Post by ninwa » Wed Oct 27, 2010 6:20 am

Feel free to close thread, problem was resolved. This has been a great exercise in learning networking! My port forwarding was not properly configured (set for TCP but not UDP).

Post Reply

Who is online

Users browsing this forum: Google [Bot] and 11 guests