• OOSocks
    279 replies, posted
[QUOTE=The-Stone;24077520]Yeah, probably helps us doing nifty stuff :)[/QUOTE] I smell networked, cross-server usermessages
[QUOTE=Python1320;24079613]I smell networked, cross-server usermessages[/QUOTE] I smell liquid petroleum gas... this can't be good.
[QUOTE=Python1320;24069452]If you want it right now I can give what I have but I'm waiting for stoned to come online so he could make what he started. Screw it, i'll just paste it here: [url]http://iriz.pastebin.com/gYdy4yU8[/url][/QUOTE] Apparently the same code doesn't work in linux though :( [CODE] docteur Tourini .::PGn::. killed Python¹³²º using fists [D]octeur [M]aboule: bunny hop : P [Luadev Server] STEAM_0:0:13073749//stonedoos.lua running on server Querying server... ./barney: line 180: 19988 Segmentation fault (core dumped) $CMD booting guarddog Server crashed (Returned 139) No pid file? Cannot access memory at address 0xf7771658 Cannot access memory at address 0xee9490fc /home/srcds/srcds/orangebox/debug.cmds:4: Error in sourced command file: Cannot access memory at address 0xf7771658 booting guarddog CMD: /home/srcds/srcds/orangebox/srcds_linux -ip 88.191.102.162 +ip 88.191.102.162 -port 27015 -game garrysmod -pidfile /home/srcds/srcds/orangebox/srcds.pid -tickrate 33 -maxplayers 64 +map gm_construct_flatgrass_v5 Using breakpad minidump system Using breakpad crash handler Console initialized. ConVarRef mat_dxlevel doesn't point to an existing ConVar Game.dll loaded for "Garry's Mod" [/CODE]
[QUOTE=haza55;24072643]Do you guys want a BinWrite object?[/QUOTE] Yes! I'm using my own lua BinWrite : [url]http://meeeeoooow.pastebin.com/6WxN6Juh[/url] but you can't use Floats / Doubles, and you have to Unescape strings recieved with BinRead (as \n breaks RecieveLine...) [QUOTE=Python1320;24069452]If you want it right now I can give what I have but I'm waiting for stoned to come online so he could make what he started. Screw it, i'll just paste it here: [url]http://iriz.pastebin.com/gYdy4yU8[/url][/QUOTE] Thanks a lot, I fixed mine with the help of yours :D [code] valid = true max_ply = 14 game_ver = 1.0.0.94 dir = garrysmod dedi = d typ = 73 os = w num_ply = 9 appID = 4000 secure = true name = Gluttony - Lots of Maps and Mods ver = 15 pwd = false game = Sandbox num_bots = 0 map = gm_atomic[/code] [url]http://meeeeoooow.pastebin.com/YJe4MWgZ[/url]
[QUOTE=Python1320;24080833]Apparently the same code doesn't work in linux though :([/QUOTE] The module doesn't even work under linux at all for me, it just does nothing.
I updated linux and windows. Linux has better thread shutdown.
Almost got server queries working (receiving players etc too) Accidently sent 200 A2S_PLAYER packets the the IP in DarkTyrael's link. [editline]05:31PM[/editline] Oh god i just accidently sent another 200 :ohdear:
[QUOTE=Tobba;24109327]Oh god i just accidently sent another 200 :ohdear:[/QUOTE] xD About my BAD error, I just updated the win dll, and I connected successfully to my Srcds :) I'll do a test with multiple users soon.
Latest version on linux now works with my unchanged server query script, no crashes even after repeated query. I haven't tested on shutdown(mapchange) yet, though.
Multi users works, but the server crash when I close it. I'll take a screenshot the next time it happen (it's something about CThreads)
I get a NOT_CONNECTED error on a UDP socket, but only if i call Send a later than the tick the socket is created [editline]10:54PM[/editline] Actually nevermind, i was doing something wrong. works now
Can someone give a simple example how to send a Int or a Bool to another server? I have no idea what i'm doing here.
[QUOTE=_Chewgum;25029199]Can someone give a simple example how to send a Int or a Bool to another server? I have no idea what i'm doing here.[/QUOTE] You have to convert everything to bytes. Int to bytes: [lua] function ITOB( i ) local a = math.floor(i/(1<<24))%256 local b = math.floor(i/(1<<16))%256 local c = math.floor(i/(1<<8))%256 local d = math.floor(i)%256 return a,b,c,d end [/lua] Bytes to int: [lua] function BTOI(a,b,c,d) return a*(1<<24)+b*(1<<16)+c*(1<<8)+d end [/lua] As for boolean you just send one byte as 0 or 1.
[QUOTE=ralle105;25042591]You have to convert everything to bytes. Int to bytes: [lua] function ITOB( i ) local a = math.floor(i/(1<<24))%256 local b = math.floor(i/(1<<16))%256 local c = math.floor(i/(1<<8))%256 local d = math.floor(i)%256 return a,b,c,d end [/lua] Bytes to int: [lua] function BTOI(a,b,c,d) return a*(1<<24)+b*(1<<16)+c*(1<<8)+d end [/lua] As for boolean you just send one byte as 0 or 1.[/QUOTE] I know how to use bytes and that. I meant, can anyone give some example how to use OOSock to send a value to another server.
When i use this module it seems to make my servers cpu usage go sky high. I have used some of the simple example bits of code. My average server usage on one of my servers was around 5/10% now it's going around 30% even without clients and when nothing is really happening on the server, any real ideas why this would be happening?
Here's a useful patch (SVN patch format): [code] Index: ThreadedSocket.h =================================================================== --- ThreadedSocket.h (revision 127) +++ ThreadedSocket.h (working copy) @@ -976,7 +976,10 @@ result->callId = call->callId; result->secondary = accept(socket->m_iSocket, (struct sockaddr*)&their_addr, &size); - + + char *peer = inet_ntoa(((sockaddr_in *)&their_addr)->sin_addr); + result->peer = CString(peer, strlen(peer)); + result->error = socket->CheckError(result->secondary, 0); socket->PushResult(result); [/code] What this does is actually fill the peer argument on SCKCALL_ACCEPT callbacks, so you can get the remote IP of the socket that has just been accepted.
[QUOTE=_Chewgum;25046730]I know how to use bytes and that. I meant, can anyone give some example how to use OOSock to send a value to another server.[/QUOTE] [lua] -- Server 1 local Target_IP = "123.456.789.010"; local Target_Port = 1337; local Recieve_Port = 1338; -- Lookout you cant bind mutliple aplications to the same port on the same box !! require("oosocks"); local connection = OOSock(IPPROTO_UDP); connection:SetCallback(function(socket, callType, callId, err, data, peer, peerPort) if(callType == SCKCALL_BIND && err == SCKERR_OK) then -- This run atm you bind your socket (aka when connection:Bind i ran) print("Socket Bound."); end if(callType == SCKCALL_SEND && err == SCKERR_OK) then -- This is run atm you send a package. print("Sent."); end if(callType == SCKCALL_REC_DATAGRAM && err == SCKERR_OK) then -- This is ran atm you recieve a package of the form "DATAGRAM" print("The max players on server 2 is " .. data .. "\n"); -- You probably want to do something with this information other then printing in in console. connection:ReceiveDatagram(); -- Atm We get a package we start waiting for the following package. end if(err != SCKERR_OK) then -- Any error is catched using this socket:Close(); -- We close the socket because an error has acured. end end); connection:Bind("", Recieve_Port); -- We bind the socket to wait for incomming packages. connection:Send(tostring(MaxPlayers()), Target_IP, Target_Port); ----- END SERVER 1 ----- ----- SERVER 2 ----- local Target_IP = "123.456.789.010"; local Target_Port = 1338; local Recieve_Port = 1337; -- Lookout you cant bind mutliple aplications to the same port on the same box !! require("oosocks"); local connection = OOSock(IPPROTO_UDP); connection:SetCallback(function(socket, callType, callId, err, data, peer, peerPort) if(callType == SCKCALL_BIND && err == SCKERR_OK) then -- This run atm you bind your socket (aka when connection:Bind i ran) print("Socket Bound."); end if(callType == SCKCALL_SEND && err == SCKERR_OK) then -- This is run atm you send a package. print("Sent."); end if(callType == SCKCALL_REC_DATAGRAM && err == SCKERR_OK) then -- This is ran atm you recieve a package of the form "DATAGRAM" print("The max players on server 1 is " .. data .. "\n"); -- You probably want to do something with this information other then printing in in console. connection:ReceiveDatagram(); -- Atm We get a package we start waiting for the following package. end if(err != SCKERR_OK) then -- Any error is catched using this socket:Close(); -- We close the socket because an error has acured. end end); connection:Bind("", Recieve_Port); -- We bind the socket to wait for incomming packages. connection:Send(tostring(MaxPlayers()), Target_IP, Target_Port); ----- END SERVER 2 ------ -- If you want to send multiple packages with different data. -- The way you want to go would probably be to make the first characther of the data-string you receive to be a indentifyer to identify the package kind.[/lua]
- Added BinWrite for Send command. (Not on SendLine, you can add the \n yourself :D) - Fixed crash on map change for single core machines or overloaded machines. - Hopefully increased the throughput. - Fixed cpu noming. - Added IP and Port to Accept call. Thanks DfReisan for that info(silly me). I will compile a Linux and Mac update soon.
Great update thanks for fixing the cpu issue :)
I've noticed an odd bug with the module, when the server closes the socket (socket:Close()), the client gets spammed with empty (data == "") ReceiveLine requests that have the errorcode of OK. I'm using this on the client: [lua] require("OOSocks") IP = "localhost" PORT = 1555 function clientsock_Callback(socket, callType, callId, err, data, peer, peerPort) if(err == SCKERR_CONNECTION_RESET) then print("[CLIENT] Disconnected.") end if( callType == SCKCALL_REC_LINE ) then print("[CLIENT] Received \"" .. data .. "\"" ) socket:ReceiveLine() end if( callType == SCKCALL_CONNECT && err == SCKERR_OK ) then socket:ReceiveLine() end end clientsock = OOSock( IPPROTO_TCP ) clientsock:SetCallback(clientsock_Callback) clientsock:Connect( IP, PORT ) [/lua] and this on the server: [lua] require("OOSocks") sockets = {} function clientsock_Callback(socket, callType, callId, err, data, peer, peerPort) if( callType == SCKCALL_REC_LINE ) then print( "[SERVER] Received \"" .. data .. "\"" ) socket:ReceiveLine() end end function serversock_Callback(socket, callType, callId, err, data, peer, peerPort) if( callType == SCKCALL_LISTEN && err == SCKERR_OK ) then print("[SERVER] Listening.") socket:Accept() end if(callType == SCKCALL_BIND && err == SCKERR_OK) then print("[SERVER] Socket Bound.") socket:Listen( 1 ) end if(callType == SCKCALL_ACCEPT) then print("[SERVER] Got a connection: "..peer) table.insert(sockets, data) data:SetCallback(clientsock_Callback) data:ReceiveLine() socket:Accept() end end serversock = OOSock( IPPROTO_TCP ) serversock:SetCallback(serversock_Callback) serversock:Bind( "", 1555 ) [/lua] Server's on the same machine as the client and it works fine, I can send and receive things, but when I close the socket on the server (lua_run for _,v in pairs(sockets) do v:Close() end), I get spammed with empty ReceiveLine callbacks on the client. I investigated this a bit and saw that you're using recvfrom in the module. recvfrom returns 0 (according to docs I've found on the net) when the socket is gracefully closed, and apparently this confuses the error check on the module or something. Please look into this. EDIT: Also, when using the Windows telnet client to connect to the server, the connection is accepted (although sometimes "randomly" drops) yet the accept callback isn't called.
[QUOTE=DfReisan;26774351]I've noticed an odd bug with the module, when the server closes the socket (socket:Close()), the client gets spammed with empty (data == "") ReceiveLine requests that have the errorcode of OK. I'm using this on the client: [lua] require("OOSocks") IP = "localhost" PORT = 1555 function clientsock_Callback(socket, callType, callId, err, data, peer, peerPort) if(err == SCKERR_CONNECTION_RESET) then print("[CLIENT] Disconnected.") end if( callType == SCKCALL_REC_LINE ) then print("[CLIENT] Received \"" .. data .. "\"" ) socket:ReceiveLine() end if( callType == SCKCALL_CONNECT && err == SCKERR_OK ) then socket:ReceiveLine() end end clientsock = OOSock( IPPROTO_TCP ) clientsock:SetCallback(clientsock_Callback) clientsock:Connect( IP, PORT ) [/lua] and this on the server: [lua] require("OOSocks") sockets = {} function clientsock_Callback(socket, callType, callId, err, data, peer, peerPort) if( callType == SCKCALL_REC_LINE ) then print( "[SERVER] Received \"" .. data .. "\"" ) socket:ReceiveLine() end end function serversock_Callback(socket, callType, callId, err, data, peer, peerPort) if( callType == SCKCALL_LISTEN && err == SCKERR_OK ) then print("[SERVER] Listening.") socket:Accept() end if(callType == SCKCALL_BIND && err == SCKERR_OK) then print("[SERVER] Socket Bound.") socket:Listen( 1 ) end if(callType == SCKCALL_ACCEPT) then print("[SERVER] Got a connection: "..peer) table.insert(sockets, data) data:SetCallback(clientsock_Callback) data:ReceiveLine() socket:Accept() end end serversock = OOSock( IPPROTO_TCP ) serversock:SetCallback(serversock_Callback) serversock:Bind( "", 1555 ) [/lua] Server's on the same machine as the client and it works fine, I can send and receive things, but when I close the socket on the server (lua_run for _,v in pairs(sockets) do v:Close() end), I get spammed with empty ReceiveLine callbacks on the client. I investigated this a bit and saw that you're using recvfrom in the module. recvfrom returns 0 (according to docs I've found on the net) when the socket is gracefully closed, and apparently this confuses the error check on the module or something. Please look into this. EDIT: Also, when using the Windows telnet client to connect to the server, the connection is accepted (although sometimes "randomly" drops) yet the accept callback isn't called.[/QUOTE] Another update(win32), should fix the recvfrom issue. Not sure about why that's happening with telnet? Has that always happened, or is it recent.
[QUOTE=haza55;26774107] - Fixed crash on map change for single core machines or overloaded machines. [/QUOTE] Do you have any information on this? My servers often crash before the server can change map when changing map, would this possibly be the cause of it?
[QUOTE=slayer3032;26779120]Do you have any information on this? My servers often crash before the server can change map when changing map, would this possibly be the cause of it?[/QUOTE] Why not update and check it out. It was crashing for me on a single core esxi vm. But not on my quad and six core. The reason was, when closing the thread, it would unallocate the threads's function, but the thread still had to run a few more instructions, but the PC of the thread was pointing to unallocated memory causing the error. I had already implemented a wait function for the thread to leave the main execution loop and assumed it would all be ok... but apparently SetEvent always yields.
[QUOTE=haza55;26792617]Why not update and check it out. It was crashing for me on a single core esxi vm. But not on my quad and six core. The reason was, when closing the thread, it would unallocate the threads's function, but the thread still had to run a few more instructions, but the PC of the thread was pointing to unallocated memory causing the error. I had already implemented a wait function for the thread to leave the main execution loop and assumed it would all be ok... but apparently SetEvent always yields.[/QUOTE] You've yet to compile it for linux so I cannot try it out yet.
[url]http://g.iriz.org/~srcds/modules/[/url] Most often the latest, like now
Does somebody have a nice tutorial on how to work with sockets?
Look at first post, then look at the posts scattered in the thread, the lua_webserver on haza's svn and those released cross server chats somewhere. If you still don't figure stuff out you're pretty much doomed.
[QUOTE=Python1320;26796147][url]http://g.iriz.org/~srcds/modules/[/url] Most often the latest, like now[/QUOTE] His linux module hasn't been updated according to the revision logs, so yeah. [url]http://gmod-haza.googlecode.com/svn/trunk/gm_oosocks/[/url] He's only been updating the windows one from what I see. [url]http://code.google.com/p/gmod-haza/source/detail?r=133[/url] Now he needs to update the linux one so I can see if I can bring back my 4 other servers. ;)
[QUOTE=slayer3032;26806068][QUOTE=Python1320;26796147][url]http://g.iriz.org/~srcds/modules/[/url] Most often the latest, like now[/QUOTE] His linux module hasn't been updated according to the revision logs, so yeah. [url]http://gmod-haza.googlecode.com/svn/trunk/gm_oosocks/[/url] He's only been updating the windows one from what I see. [url]http://code.google.com/p/gmod-haza/source/detail?r=133[/url] Now he needs to update the linux one so I can see if I can bring back my 4 other servers. ;)[/QUOTE]I was hinting that I had compiled the latest version (as of 2010-Dec-18) and it worked. I haven't tested map changing though so that's up to you.
Updated Linux.
Sorry, you need to Log In to post a reply to this thread.