[QUOTE=haza55;22277674]I have corrected some mistakes in the documentation and have also updated the Win32 bins to take ip/port as arguments in Send and SendLine.
I'm sorry for any mistakes, I kinda have a lot of work to do.
There is no timeout needed, as the thread will not return a callback unless data has been collected or the socket has somehow died.
Regarding the original luasockets module. It was not salvageable with the recent updates. If you want to go make one, go right ahead. But most developers want a non blocking threaded library(so do I), so thats what I made.[/QUOTE]
Could you add a UDP example to the OP?
Yeah pretty much doesn't work as expected.
[code]
] lua_run TEST= OOSock(IPPROTO_UDP) TEST:Bind("192.168.1.103", 2010) TEST:SetCallback(print)
> TEST= OOSock(IPPROTO_UDP) TEST:Bind("192.168.1.103", 2010) TEST:SetCallback(print)...
OOSock: 2F221998 4 1 4
] lua_run local s = OOSock(IPPROTO_UDP) s:SendLine("Hello", "192.168.1.103", 2010)
> local s = OOSock(IPPROTO_UDP) s:SendLine("Hello", "192.168.1.103", 2010)...
] lua_run TEST:ReceiveLine()
> TEST:ReceiveLine()...
OOSock: 2F11A208 2 2 0 0.0.0.0:
[/code]
It also crashes with no dump when I disconnect from the server.
Ok I've fixed UDP.
Check OP for example.
I've updated Win32, Linux will be updated soon.
[editline]05:42AM[/editline]
Also I've said this to many people, but not here yet.
To be most reliable, please set the callback before you call anything(Before Bind and Connect).
If no callback is set, callbacks will be disposed.
[editline]06:23AM[/editline]
Linux bins have been updated.
Yea I'm sorry about the tone of my post, I was a bit crabby as I'd been trying to get a simple server working for 2 hours and no matter what I tried it doesn't seem to work.
I know this is a big undertaking and I support this project but it just seems like it's done but clearly there's work to be done to finalize and make it perfect.
I know about the non-blocking and threading and it's all well and good, but like I said I'm not able to receive any data. I even tested with telnet connecting to the port and I get immediately disconnected and further trying to send data from the lua it only receive empty data and sometimes the Receive doesn't receive anything at all.
I may look in the source and try to find something out but I have too many projects atm but a socket library in gmod is important to my work.
[QUOTE=JetBoom;22285912]It also crashes with no dump when I disconnect from the server.[/QUOTE]
Yes, also when you try to changelevel.
[QUOTE=bringitonbitch;22296915]Yea I'm sorry about the tone of my post, I was a bit crabby as I'd been trying to get a simple server working for 2 hours and no matter what I tried it doesn't seem to work.
I know this is a big undertaking and I support this project but it just seems like it's done but clearly there's work to be done to finalize and make it perfect.
I know about the non-blocking and threading and it's all well and good, but like I said I'm not able to receive any data. I even tested with telnet connecting to the port and I get immediately disconnected and further trying to send data from the lua it only receive empty data and sometimes the Receive doesn't receive anything at all.
I may look in the source and try to find something out but I have too many projects atm but a socket library in gmod is important to my work.
Yes, also when you try to changelevel.[/QUOTE]
All these issues were just fixed ;)
Constructive feedback and bug reports go a long way :)
I used your example code (nothing was changed) to test the UDP support and I got this:
I run the script 2 times:
[Code]
] lua_openscript test.lua
Running script test.lua...
Bound.
Sent.
Got 'rofl' from 127.0.0.1:37267
] lua_openscript test.lua
Running script test.lua...
Bound.
Sent.
[/Code]
On the 2ed run, you can see, there was no data input.
The port where I get my data is different as the port is given in the script, the game also crashed with a "Lua Error Dump" Error on disconnect or on closing.
Odd. I'll have a look at it later. Probally some garbage collection issue intertwined with binding to a used port.
Any more problems with this. I would like to finish it and shelve it.
[QUOTE=haza55;22405004]Any more problems with this. I would like to finish it and shelve it.[/QUOTE]
Still crashing on disconnect
[QUOTE=bromvlieg;22415191]Still crashing on disconnect[/QUOTE]
Protocol? Test code? MDMPs? Using latest bins?
[QUOTE=haza55;22416466]Protocol? Test code? MDMPs? Using latest bins?[/QUOTE]
[lua]
Keplop.Data.Socket = OOSock(IPPROTO_UDP)
Keplop.Data.Socket:SetCallback(function(socket, callType, callId, err, data, peer)
if err ~= 0 and err ~= 1 then print("ERRROR") return end
print(socket, callType, callId, err, data, peer)
if(callType == 4 && err == SCKERR_OK) then
Keplop.Data.Socket:ReceiveDatagram()
end
if(callType == 7) then
ip, port = string.Explode(":", peer)[1], string.Explode(":", peer)[2]
print(data, ip, port)
Keplop.Data.Socket:ReceiveDatagram()
end
if(callType == 3) then
chat.AddText("Send")
end
end)
Keplop.Data.Socket:Bind("", math.random(6113,6119))
[/lua]
Thats the code
and after you "remove" the socket somehow it still is binded to that port, as i cant execute that code twice whit the same port number, it refused to recieve anything thats why i did the math.random somehow it works whit that aslong its not the same as the last port
Edit:
Im using latest bins and the [url=http://www.filefront.com/16667835/hl2_4104_crash_2010_6_6T15_10_25C0.mdmp]Crash file[/url][URL="http://www.filefront.com/16667835/hl2_4104_crash_2010_6_6T15_10_25C0.mdmp"][/URL]
[QUOTE=haza55;22416466]Protocol? Test code? MDMPs? Using latest bins?[/QUOTE]
Will you fix it?
We NEED the UDP support with a correct working port binding, because my friend has an addon for wiremod it's called [URL="http://www.wiremod.com/forum/wiremod-addons/11575-wire-socket-radio-returns-re-v-3-a.html"]Wire Socked Radio[/URL] and it needs a support for UDP with port binding and correct working origin destination.
Updated.
Added a Close function. Also changed how windows closes the thread.
[QUOTE=haza55;22484778]Updated.
Added a Close function. Also changed how windows closes the thread.[/QUOTE]
Still crashes, [url=http://www.filefront.com/16695637/hl2_4104_crash_2010_6_9T12_24_20C0.rar]Crash file[/url].
Ive downaloded the dll after youve posted.
Ok that should fix it.
[QUOTE=haza55;22485596]Ok that should fix it.[/QUOTE]
Works :buddy:
Only just noticed this. Sure beats GSocket + LuaSocket. Wish this was here [i]before[/i] I had to script a networked lobby.
What about this bug? When I send over the port 37777 to my self then I got it from port 37267.
When I send to port 37777 from port 37777 then I need it from port 37777 and not from some random port.
Here is used script and console output:
[lua]require("oosocks")
local connection = OOSock(IPPROTO_UDP);
connection:SetCallback(function(socket, callType, callId, err, data, peer)
if(callType == SCKCALL_BIND && err == SCKERR_OK) then
print("Bound.");
connection:Send("rofl", "127.0.0.1", 37777);
connection:ReceiveDatagram();
end
if(callType == SCKCALL_SEND && err == SCKERR_OK) then
print("Sent.");
end
if(callType == SCKCALL_REC_DATAGRAM && err == SCKERR_OK) then
print("Got '" .. data .. "' from " .. peer);
socket:Close()
end
if(err != SCKERR_OK) then
socket:Close()
end
end);
-- an IP of "" binds to all interfaces.
connection:Bind("", 37777);
[/lua]
[code]
] lua_openscript test.lua
Running script test.lua...
Bound.
Sent.
Got 'rofl' from 127.0.0.1:37267
[/code]
I'm using Windows 7 64 bit.
Edit: Could you split the peer argument to seperrate ip (as string) and port (as number) arguments? Some times you only need the port and some times you only need the ip. It's very annoying to split the string to 2 values with 2 different types every time you need it.
Ok try the updated DLL.
Also the last argument of the callback function is now the port.
Did you remember to swap the port number from network to host order?
37777 = 0x9391
37267 = 0x9193
:)
Something like
[code]
result->secondary = ntohs( ((sockaddr_in *)&addr)->sin_port );
[/code]
hurrrr....
Forgive me, This is spaghetti code.
Updated DLLs. Linux soon + Darwin Experimental soon.
It works fine now. :D
That makes me happy :D
Ohhhh so I can now make a gmod web-server ehh?
[editline]09:02AM[/editline]
Great, gmod is giving me some D3D errors. let me restart teh computarz
OOSocks suddenly crashed on me =/
This is the code I used:
[lua]
require("oosocks")
local connection = OOSock(IPPROTO_UDP);
local Bound = 0
local Target = ""
connection:SetCallback(function(socket, callType, callId, err, data, peer)
if(callType == SCKCALL_BIND && err == SCKERR_OK) then
print("Bound.");
Bound = 1
end
if(callType == SCKCALL_SEND && err == SCKERR_OK) then
print("Sent.");
end
if(callType == SCKCALL_REC_DATAGRAM && err == SCKERR_OK) then
if not ReadMsg(data) then print("Got '" .. data .. "' from " .. peer); end
connection:ReceiveDatagram();
end
if(err != SCKERR_OK) then
socket:Close()
end
end);
-- connection:Send("rofl", "127.0.0.1", 37777);
-- connection:ReceiveDatagram();
-- an IP of "" binds to all interfaces.
connection:Bind("", 37777);
local function ReadMsg(data)
local Ar = data.explode(" ")
local Len = 0
local I = 0
if Ar[1] == "ZONMSG:" then
I = Ar[1].len+Ar[2].len+2
Len = tonumber(Ar[2])
local Name = string.sub( data, I, I+Len )
I = I+Len+1
Text = string.sub( data, I)
for k,v in pairs(Player:GetAll()) do
k:ChatPrint(Name..": "..Text)
end
return 1
else return 0 end
end
local function Sendit(text, ply)
local T = "ZONMSG: "..string.len(ply:GetName()).." "..ply:GetName().." "..text
connection:Send(T, Target, 37777)
end
local function ISaid( ply, text, team, death )
if (string.sub(text, 1, 7) == "/target") then
Target = string.sub( text, 8 );
else if (string.sub(text, 1, 1) == "-") then
if(Target != "") then
Sendit(string.sub( text, 1 ), ply)
else
ply:ChatPrint("No target")
end
else if text == "/killsocks" then
hook.Remove( "PlayerSay", "ISaid" )
socket:Close()
ply:ChatPrint("Removed hooks and socket. Reload script to use them again.")
end
end
end
end
hook.Add( "PlayerSay", "ISaid", ISaid );
connection:ReceiveDatagram();
[/lua]
You should not be calling ReceiveDatagram inside a Think like that.
When you do ReceiveDatagram, you place a Receive call in a buffer.
ReceiveDatagram should be run once at the start, then after each successful SCKCALL_REC_DATAGRAM callback.
Ah ok, I'll try that.
Think of it like this.
You don't use Send every Think, if you only want to send 1 packet.
So
You don't use Receive every Think, if you only want to receive 1 packet.
For some reason it still crashes... (Updated the code in my post)
For a server app that waits for datagrams, there should be exactly one Receive call in the buffer at any one time?
Sorry, you need to Log In to post a reply to this thread.