Network API
I was playing with the network API, but I can't find a way to close a TCPLink's connection.
Reply
Thanks given by:
Yes, I forgot about that. Will fix tonight on train back to prague.
Reply
Thanks given by: NiLSPACE
Thanks in advance Smile
Reply
Thanks given by:
Close() is implemented; Shutdown() is somewhat problematic - LibEvent keeps the data in a buffer, so when you shut down a socket, you lose whatever LibEvent hasn't sent yet. I'm trying to find a solution to this, because it affects all connections a lot.
Reply
Thanks given by: NiLSPACE
I really like the network API Smile I now have a small webserver where you can use <?lua LuaCode ?> to add code. It even detects if it's a POST or GET request in the code ;D

I even found a use for Lua Coroutines ;D
Reply
Thanks given by:
Made a simple login/logout page:
<?lua
Client, Link = ...


local Message = ""

-- User send a post, so he probably wants to login or logout
if (Client.RequestMethod == "POST") then
	if (Client.POST['logout'] ~= nil) then
		-- The user wants to log out
		Client.SESSION['loggedin'] = false;
		Message = "You logged out"
	elseif (Client.POST['login'] ~= nil) then
		-- The user tries to log in.
		local UserName = Client.POST['username']
		local Password = Client.POST['password']
		
		if (UserName == "admin" and Password == "admin") then
			-- password and username is correct
			Client.SESSION['loggedin'] = true
			Message = "You logged in"
		else
			-- Wrong username or password
			Message = "You used the wrong username or password"
		end
	end
end


local IsLoggedIn = Client.SESSION['loggedin'];
local Form = [[
<input type="text" name="username" placeholder="username"><br>
<input type="password" name="password" placeholder="password"><br>
<input type="submit" name="login" value="login" >]]

if (IsLoggedIn) then
	Form = '<input type="submit" name="logout" value="logout">'
end

?>
<!DOCTYPE html>
<html>
<head>
</head>

<body>
	<?lua
do -- Do - end isn't needed, but it makes it easier to notice where small bits of lua code are.
	Link:Send(Message) 
end
	?>
	<form method="POST">
<?lua
do -- Do - end isn't needed, but it makes it easier to notice where small bits of lua code are.
	Link:Send(Form)
end
?>
	</form>
</body
</html>
Reply
Thanks given by:
Is it possible that the cTCPLink:Close function closes the connection before some data that was send is received? I now have to use
cRoot:Get():GetDefaultWorld():QueueTask(
	function()
		a_TCPLink:Close()
	end
)

Because otherwise the browser won't receive anything.

Oh I see in the APIDesc file that I have to use cTCPLink:Shutdown because cTCPLink:Close could do exacly what I just mentioned Wink
Reply
Thanks given by:
Exactly Smile
Reply
Thanks given by:
I'm thinking about UDP support. Since UDP doesn't have the concept of a persistent connection, I think the only interface needed would be an "Endpoint", which can be attached to a port number and either receive or send UDP datagrams.

The interface:
- cNetwork:CreateUDPEndpoint(Port, UDPCallbacks) -> cUDPEndpoint object

cUDPEndpoint methods:
- IsOpen()
- GetPort()
- Send(Data, Host, Port) - sends a datagram with the specified data payload to the specified host/port
- EnableBroadcasts() - enables the endpoint to send broadcasts (using special host/port combinations)
- Close()

UDPCallbacks:
- OnError(ErrorCode, ErrorMsg)
- OnReceivedData(Data, Host, Port) - A datagram with the specified Data payload has been received from the specified host/port
Reply
Thanks given by:
Sounds good.
Reply
Thanks given by:




Users browsing this thread: 10 Guest(s)