02-14-2015, 02:07 AM
I was playing with the network API, but I can't find a way to close a TCPLink's connection.
Network API
|
02-14-2015, 02:07 AM
I was playing with the network API, but I can't find a way to close a TCPLink's connection.
02-14-2015, 02:21 AM
Yes, I forgot about that. Will fix tonight on train back to prague.
Thanks given by: NiLSPACE
02-14-2015, 02:29 AM
Thanks in advance
02-14-2015, 08:23 AM
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.
Thanks given by: NiLSPACE
I really like the network API 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
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>
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
02-15-2015, 11:54 PM
Exactly
02-16-2015, 12:12 AM
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
02-16-2015, 01:45 AM
Sounds good.
|
« Next Oldest | Next Newest »
|