-
Notifications
You must be signed in to change notification settings - Fork 12
/
udp.lua
33 lines (24 loc) · 834 Bytes
/
udp.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
require("bromsock")
concommand.Add("hostUDP", function()
if serversock then serversock:Close() end -- to make sure we can host. Would be rather silly if we'd try to host while it's still open!
serversock = BromSock(BROMSOCK_UDP)
serversock:SetCallbackReceiveFrom(function(sockobj, packet, ip, port)
print("[S] Received:", packet, ip, port)
print("[S] R_Str:", packet:ReadStringAll())
packet:WriteString("From server!")
serversock:SendTo(packet, ip, port)
serversock:ReceiveFrom()
end)
serversock:Bind(1337)
serversock:ReceiveFrom()
end)
concommand.Add("sendUDP", function()
local clientsock = BromSock(BROMSOCK_UDP)
local packet = BromPacket()
packet:WriteStringRaw("From client!")
clientsock:SendTo(packet, "127.0.0.1", 1337)
clientsock:Close()
packet:Clear()
clientsock = nil
packet = nil
end)