• The New Net Library
    94 replies, posted
PVS is what you can see from that spot, PAS is what you can hear from that spot
[QUOTE=garry;33503734]PVS is what you can see from that spot, PAS is what you can hear from that spot[/QUOTE]Oh my god. You just made me cum a little. This is amazing.
[QUOTE=thejjokerr;33494485]By the way I couldn't find this in the thread anywhere, but the net.Receive callback is actually also gives another variable, which is a table: [CODE]1 = Player [1][[RV] TJjokerR] n = 1[/CODE] The sending player and something else?[/QUOTE] [quote=Programming in Lua: 19.1 - Array Size]Usually, a call table.setn(t, n) associates t with n in an internal (weak) table and a call table.getn(t) retrieves the value associated with t in that internal table. [b]However, if the table t has a field "n" with a numeric value, setn updates this value and getn returns it.[/b] The getn function still has a last option: If it cannot get an array size with any of those options, it uses the naive approach: to traverse the array looking for its first nil element. So, you can always use table.getn(t) in an array and get a reasonable result.[/quote]
Would anyone know what would cause the following behavior? Net lib wont start sending messages (from server) until I execute sv_allowdownload 1 in server console. This was tested in both listen and dedicated, where download was allowed in both upon start-up of the server. net.Send( ply ) sending net message to all players on server? ply being one player entity. I'm just wondering if anyone is experiencing anything similar while I continue to comb my gamemode for anything I have done incorrectly. edit: This actually just seems to affect the first player that connects, subsequent players start receiving net messages, but messages sent to a single player still seem to be broadcasted.
Sending a Table that contains a Table in Net lib causes the sub table to be sent as a number (258) Also seems to not send empty tables {}, can be annoying when sending tables structures.
[QUOTE=thejjokerr;33512702]Sends as a different number for me, I think it's taking a character from the key string and converts it to the numerical code. Didn't report it as Garry said he was still working on it.[/QUOTE] [url]http://www.facepunch.com/threads/1143704?p=33504343&viewfull=1#post33504343[/url]
I have two net messages that are sent to the clients by the server. [code] net.Receive("UpdateRoundInfo", function(size) ROUND_TIME = net.ReadFloat() ROUND_NUMBER = net.ReadFloat() print(ROUND_NUMBER) end) net.Receive("StartRound", function(size) ROUND_TIME = net.ReadFloat() ROUND_NUMBER = net.ReadFloat() RoundStart() print(ROUND_NUMBER) end) [/code] Here's the code I'm using to call them: [code] if ROUND_NUMBER == 0 and #player.GetAll() >= MINIMUM_PLAYERS then net.Start("StartRound") net.WriteFloat(ROUND_TIME) net.WriteFloat(ROUND_NUMBER) net.Broadcast() RoundStart() print("A") else net.Start("UpdateRoundInfo") net.WriteFloat(ROUND_TIME) net.WriteFloat(ROUND_NUMBER) net.Broadcast() print("B") end [/code] The net message SHOULD be sent, because the server prints both A and B when they should be called. The client prints the round number (So it is receiving) "UpdateRoundInfo", but "RoundStart" is never called. I've tried printing "HI" and stuff like that, so it's not a matter of ROUND_NUMBER being nil. No errors or nothing it's driving me absolutely insane, plus I can't even check the Wiki since it decided to go down for a few hours.
My problem is similar Kopimi, May not be related but try issuing sv_allowdownload 1 on the server console, before sending begin round net message. I found doing this (or reconnecting) tended to make the unsent net messages suddenly start sending/receiving.
[QUOTE=Science;33503597][h2]Im Currently Working On The Wiki Page If Anyone Wants To Help[/h2] [url]http://wiki.garrysmod.com/?title=Net[/url][/QUOTE] Learn to spell rec[B]ei[/B]ve please. I recreated the page [b][url=wiki.garrysmod.com/?title=Net.Receive]Net.Receive [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b] because you had plenty of typos that would confuse people as to why net.rec[B]ie[/B]ve wouldn't work. Also I improved your example :v:.
It also doesn't only take a unique identifier as it's argument. It takes an identifier and a function, just like usermessage.Hook. It doesn't return a number either. Those inconsistencies tend to bug me...
Cleaned up the page a bit more.
on net.Receive serverside, is there a way to know from which client the message originated? That would be good to know
[QUOTE=Kamshak;36030122]on net.Receive serverside, is there a way to know from which client the message originated? That would be good to know[/QUOTE] [code]net.Receive( "name", function( length, player ) end)[/code] Also: [url]http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/index5b6a.html?title=Net&oldid=55437[/url]
Am I able to replace all my usermessages/concommands with this? I'd love too. Right now anytime I update the table server-side I send a usermessage which the client-side has hooked and updates the local table. To display on VGUI menus and such. But I'm unable to hook messages, so I'm assuming I couldn't really replace ether? Thanks. [b]EDIT:[/b] Nevermind, I just saw the old Wiki post.
Well, hopefuly net will be as good as umsg.
I've been experimenting with the Source engine (while creating a playground mod) and found out how to do this. If Garry uses a similar way, then I can tell you it is better than usermessages. One thing that bothers me though, is how Garry sends the data. Does he always sends the 65535 (or something like that) bytes (which is rather unlikely) or if he sends a number detailing the amount of bits sent (since I've been unable to actually make the engine do that for itself with its bit buffers, I assume this is needed).
Don't mean to double post. But why does this not work? [lua] if SERVER then local test_table = { "eggs", "cheese", "apple", 100200, 3.4567, Vector(1.2345,800,-900), Entity(1) } util.AddNetworkString("test_message") net.Start("test_message") net.WriteTable(test_table) net.Broadcast() print("sending..") end if CLIENT then net.Receive("test_message", function(length) MsgN("Got Message. Len: " , length) PrintTable(net.ReadTable()) end); end [/lua] Dumps: [QUOTE=GMod Console] Got Message. Len: 659 [@lua\includes\modules\net.lua:133] Couldn't read type 4325378 Error [C]:-1 ReadType lua\includes\modules\net.lua:133 ReadTable lua\includes\modules\net.lua:81 func lua\derp2.lua:5 unknown lua\includes\modules\net.lua:26 [/QUOTE]
You shouldn't send the message right after registering the message name. About the rest, I have no idea. I've scrolled through the net Lua module and everything seems fine.
[QUOTE=danielga;36597881]You shouldn't send the message right after registering the message name. About the rest, I have no idea. I've scrolled through the net Lua module and everything seems fine.[/QUOTE] net.WriteTable is broken because of Garry removing net.WriteLong and replacing it with net.WriteInt and forgetting to change the occurrences of it.
He'd need to make it net.WriteUInt(val, 32), not net.WriteInt.
So is a quick fix to edit the "net.lua" file?
Just define the functions you need, I posted them in another thread in the gm13 section, see yourself.
[QUOTE=Drak_Thing;36596693]Don't mean to double post. But why does this not work? [lua] if SERVER then local test_table = { "eggs", "cheese", "apple", 100200, 3.4567, Vector(1.2345,800,-900), Entity(1) } util.AddNetworkString("test_message") net.Start("test_message") net.WriteTable(test_table) net.Broadcast() print("sending..") end if CLIENT then net.Receive("test_message", function(length) MsgN("Got Message. Len: " , length) PrintTable(net.ReadTable()) end); end [/lua] Dumps:[/QUOTE] You want to register the message name a few seconds before using it. Your code looks fine either way, Garry just needs to fix net tables since his last update broke them.
Is anyone else getting funny results from net.ReadUInt and net.ReadInt? I've heard reports of them being broken and garry having fixed them, but in the latest GM13 version, I'm getting numbers much larger than 255 from net.ReadUInt( 8 ).
It's fixed in the next update.
[QUOTE=thomasfn;36634008]Is anyone else getting funny results from net.ReadUInt and net.ReadInt? I've heard reports of them being broken and garry having fixed them, but in the latest GM13 version, I'm getting numbers much larger than 255 from net.ReadUInt( 8 )[/QUOTE] It works, but the bits have to be the second argument for net.ReadInt / net.ReadUInt. (net.ReadUInt(nil,8) / net:ReadUInt(8)) net.ReadEntity seems to be broken though. It always returns NULL. [EDITLINE]-[/EDITLINE] net.WriteBit also seems to ignore the first argument and use the second instead.
[EDITLINE]-[/EDITLINE] net.WriteBit also seems to ignore the first argument and use the second instead.[/QUOTE] That might be related because it uses the same function. In any case you should report that too just to make sure.
Sorry, you need to Log In to post a reply to this thread.