Outside of any hook. If I do clients[#clients]:SendLine"Greetings"
I receive the message only after sending something from the other end :s
Probably because of the issued ReceiveLine?
[QUOTE=Python1320;23681701]Outside of any hook. If I do clients[#clients]:SendLine"Greetings"
I receive the message only after sending something from the other end :s
Probably because of the issued ReceiveLine?[/QUOTE]
Receive and Send buffers are supposed to be separate. I'll have a look at it thou.
Queueing mechanism seems to suck.
[lua]sock:ReceiveLine()
sock:Send"Hax"
sock:Send"Hax"
sock:Send"Hax"
sock:ReceiveLine()[/lua]
This code will send only after it receives. If it does not receive anything, my data will never be sent. Additionally, after it receives one line, it will send one "hax" and then wait for another line before sending rest of data.
If someone needs to wait for data while sending data on demand, and do that quick, this module is far worse that luasocket.
A possible solution is having two threads, one for sending and other for receiving.
This module works fine.
If you have a problem, give me a full blown example. It is most likely you are doing something wrong.
I have a fully working HTTP server with this module.
Are you using the latest bins? Are you using linux or windows? What is on the other end of the socket?
Latest (or almost latest) bins, both windows and linux, on other end - luajit with luasocket doing send(recv()).
Code:
[lua]local rs = {"x.x.x.x",27020}
RETR_Socket = OOSock(IPPROTO_TCP)
RETR_Socket:SetCallback(function(sc,ct,id,err,data,ip,port)
print("Sox callback")
if err ~= SCKERR_OK then ErrorNoHalt("Sock Error!"..err.." "..data) SocketReconnect() end
if ct == SCKCALL_CONNECT then
sc:ReceiveLine() //start it
elseif ct == SCKCALL_REC_LINE then
if data:find"HEARTBEAT\r?\n?" then
sc:Send("HEARTBEAT2\r\n")
RETR_LHb = os.time()
return
end
local dt = string.match(data,"DATA: (%S+) ")
if dt then
//stuff about processing data
end
timer.Simple(0.1, function() sc:ReceiveLine() end) //otherwise sends can be fucked up
end
end)
RETR_Socket:Bind("",0)
RETR_Socket:Connect(rs[1],rs[2])
function SocketPreChangeLevel()
if RETR_Socket then //to avoid crashing
RETR_Socket:Close() //anyways it crashes on mapchange
RETR_Socket = nil //probably problem of old version
end
end
hook.Add("Shutdown", "SocketShutdown", SocketPreChangeLevel)
function SocketReconnect()
RETR_Socket:Connect(rs[1],rs[2])
end
function SendMessage(dt,data)
RETR_Socket:Send("DATA: "..dt.." "..data.."\r\n")
end[/lua]
When luasocket was working in gmod, I was able to get almost instant message exchange between servers. With OOSocks I have to wait either for heartbeat or for incoming message to send my data.
My current solution is my own luasocket-like module :D
Updated windows and linux, should be fixed now.
None of the http examples worked, any ideas?
Do not test them on empty server. Add a bot, then run examples.
And give us more info, if we don't know anything - we can't help.
Why would I need a bot to get data from a php script, I have a script that on a website that takes two values in, does a mySQL query and spits out a 1 or a 0, I want to be able to get a response by what ever the user put into the two text field. I don't know if theres an easier way but after digging around for 30 minutes, I could only find this becouse LuaSocket doesnt work.
[QUOTE=kna_rus;23919157]Do not test them on empty server. Add a bot, then run examples.
And give us more info, if we don't know anything - we can't help.[/QUOTE]
Did that update fix your problem?
@pak5695: this is how source servers are made. Think hook won't be called unless there are players on server. All threaded modules are using Think hook for checking results.
@haza: I have my own module now, but after reading your code I would say that it is still not fixed. You are using select() wrong. First argument is "highest-numbered file descriptor plus 1", not zero. As you have only one file descriptor (socket itself) is should be (socket->m_iSocket+1). This seems to be reason why all recv calls block until they get data.
It's ignored on windows, so that was probally what my thinking was. Are you using linux? Cause then that would explain why its blocking, select would return an error and then the read set wouldn't have changed.
I'll update linux + windows, and if you would be so kind as to test it, I would be grateful.
[QUOTE=haza55;21750683]
OOSocks is multi-threaded, object orientated callback based module.
[/QUOTE]
:geno:
I guess I'm off to the dumb folk section where things makes sense again...
Does anyone know what BAD error mean in a CONNECT callback?
[code]Socket : Error (Clientside)
----- ----- ----- -----
Error : SCKERR_BAD
CallType : SCKCALL_CONNECT
CallID : nil
----- ----- ----- -----[/code]
I'm getting this error when I try to connect to my dedicated server's OOSocks.
Also, it works perfectly when I test it in Singleplayer (both client and server), so I think the error doesn't come from my code...
BAD means it could be anything that isn't included in the error list.
This is because I can only translate so many errors, since some don't exists under the same name in windows and linux.
If you can show us your code maybe we can help.
[QUOTE=DarkTyrael;23987801]Does anyone know what BAD error mean in a CONNECT callback?
[code]Socket : Error (Clientside)
----- ----- ----- -----
Error : SCKERR_BAD
CallType : SCKCALL_CONNECT
CallID : nil
----- ----- ----- -----[/code]
I'm getting this error when I try to connect to my dedicated server's OOSocks.
Also, it works perfectly when I test it in Singleplayer (both client and server), so I think the error doesn't come from my code...[/QUOTE]
Do you rent a server or do you rent a box ?
[QUOTE=ColdFusion;23999624]Do you rent a server or do you rent a box ?[/QUOTE]
I'm hosting it on the same PC I'm running the game.
Here's the Client connection / Server listening code:
[url]http://meeeeoooow.pastebin.com/cLTV1uVq[/url]
Waiting for haza do fix incoming data :cop:
[QUOTE=DarkTyrael;24004998]I'm hosting it on the same PC I'm running the game.
Here's the Client connection / Server listening code:
[url]http://meeeeoooow.pastebin.com/cLTV1uVq[/url][/QUOTE]
Fixed.
[lua]function Mw.Connect()
if Mw.Connected then Mw.Disconnect(true) end
g_Ready = false
-- Create the socket, bind it, connect
Mw.Socket = OOSock(IPPROTO_TCP)
Mw.Socket:SetBinaryMode(true)
Mw.Socket:SetCallback(Callback)
Mw.Socket:Connect(Mw.CV.ServerIP:GetString(), Mw.CV.ServerPort:GetInt())
end
[/lua]
Fixed.
[lua]Mw.Err = {}
Mw.Err[SCKERR_OK] = "SCKERR_OK"
Mw.Err[SCKERR_NOT_CONNECTED] = "SCKERR_NOT_CONNECTED"
Mw.Err[SCKERR_CONNECTION_RESET] = "SCKERR_CONNECTION_RESET"
Mw.Err[SCKERR_TIMED_OUT] = "SCKERR_TIMED_OUT"
Mw.Err[SCKERR_BAD] = "SCKERR_BAD"
Mw.CType = {}
Mw.CType[SCKCALL_CONNECT] = "SCKCALL_CONNECT"
Mw.CType[SCKCALL_REC_SIZE] = "SCKCALL_REC_SIZE"
Mw.CType[SCKCALL_REC_LINE] = "SCKCALL_REC_LINE"
Mw.CType[SCKCALL_SEND] = "SCKCALL_SEND"
Mw.CType[SCKCALL_BIND] = "SCKCALL_BIND"
Mw.CType[SCKCALL_ACCEPT] = "SCKCALL_ACCEPT"
Mw.CType[SCKCALL_LISTEN] = "SCKCALL_LISTEN"
Mw.CType[SCKCALL_REC_DATAGRAM] = "SCKCALL_REC_DATAGRAM"[/lua]
[QUOTE=haza55;24006305]Fixed.
[lua][/QUOTE]
Done.
Still getting the same errors:
Working in Singleplayer
BAD - CONNECT (client) using srcds or "Create Multiplayer" in GMod
I'll open my ports and ask someone else to connect to my server...
Just tried that: We only got timed out errors on connect...
(Not because of ports, as he can connect to my srcds)
What port are you using?
[QUOTE=haza55;24055241]What port are you using?[/QUOTE]
We tried with ports 80, 15739, 28013.
Got server query to work, binary read seems to work:
[CODE]
] lua_openscript_cl stonedoos.lua
Running script stonedoos.lua...
Querying server...
[Server Query] Call: Send - Error: Ok
[Server Query] Call: Datagram - Error: Ok
size:173
RawData: '����IPython1320 and CapsAdmin's Server#gm_construct_flatgrass_v5#garrysmod#QBox#�#dl#1.0.0.94#��i@���@garrysmod94,gm:qbox,PAC2,build,fishingmod,meta,sandbox#�######'
------------------
protocol:I
servername:Python1320 and CapsAdmin's Server
map:gm_construct_flatgrass_v5
gamename:garrysmod
gamedesc:QBox
appid:4000
players:14
maxplayers:15
bots:0
servertype:d
ostype:l
passworded:0
secure:1
gameversion:1.0.0.94
EDF:177
[/CODE]
Now if stoned didn't vanish every time I want to tell (or ask) him something...
[QUOTE=Python1320;24065014]Got server query to work[/QUOTE]
Nice, can you show us the code please?
Actually, all my server queries tests failed...
[QUOTE=DarkTyrael;24069117]Nice, can you show us the code please?
Actually, all my server queries tests failed...[/QUOTE]
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]
My script which worked under windows doesn't seem to work under linux, I'm not sure what is wrong but it doesn't seem like data is sending what so ever.
[QUOTE=Python1320;24065014]Got server query to work, binary read seems to work:
Now if stoned didn't vanish every time I want to tell (or ask) him something...[/QUOTE]
Sorry man, just PM me right here, not going to be online on steam for the next week :\
Oh and nice work :smug:
Do you guys want a BinWrite object?
[QUOTE=haza55;24072643]Do you guys want a BinWrite object?[/QUOTE]
Yeah, probably helps us doing nifty stuff :)
Sorry, you need to Log In to post a reply to this thread.