So I've been working on my game (which had this udp server/client relationship) recently, I eventually got this udp bug again.. After a lot of time spent, I just figured it out.
Basically the issue is that mIRC will close the udp socket when you tell it to send a packet to a "wrong" ip/port combination.
First, two smalls issues I just came accross, this is all tested on 7.39 beta4, but should certainly behave the same on beta6.
1) "/sockudp -k SERVER" doesn't do anything, I think it should report a syntax error.
2) "/sockudp -kn SERVER" triggers on sockwrite with $sockerr set to 3 with the winsock error message: "[10047] Address family not supported by protocol family", should report a syntax error as well
Now the original issue:
on *:udpread:SERVER:{
if ($sockerr) { echo -s on udpread error on SERVER: $v1 - $sock(SERVER).wsmsg | return }
var %a
sockread %a
if (!$sockbr) return
echo -s line recieved on SERVER from $sock(SERVER).saddr $sock(SERVER).sport : %a
sockudp -kn SERVER $sock(SERVER).saddr $sock(SERVER).sport WORLD
}
on *:sockclose:SERVER:{
if ($sockerr) { echo -s on sockclose error on SERVER: $v1 - $sock(SERVER).wsmsg | return }
echo -s on sockclose on SERVER, no error
}
on *:sockwrite:SERVER:{
if ($sockerr) { echo -s on sockwrite error on SERVER: $v1 - $sock(SERVER).wsmsg | return }
echo -s on sockwrite on SERVER, no error
}
on *:udpread:CLIENT*:{
if ($sockerr) { echo -s on udpread error on $sockname $+ : $v1 - $sock(SERVER).wsmsg | return }
var %a
sockread %a
if (!$sockbr) return
echo -s line recieved on CLIENT $sockname from $sock($sockname).saddr $sock($sockname).sport : %a
}
on *:sockclose:CLIENT*:{
if ($sockerr) { echo -s on sockclose error on CLIENT $sockname $+ : $v1 - $sock($sockname).wsmsg | return }
echo -s on sockclose on CLIENT $sockname $+ , no error
}
on *:sockwrite:CLIENT*:{
if ($sockerr) { echo -s on sockwrite error on CLIENT $sockname $+ : $v1 - $sock($sockname).wsmsg | return }
echo -s on sockwrite on CLIENT $sockname $+ , no error
}
Execute:
/sockudp -k SERVER 8001
/sockudp -kn CLIENT1 127.0.0.1 8001 HELLO
/sockudp -kn CLIENT2 127.0.0.1 8001 HELLO
/sockclose CLIENT2
/sockudp -kn SERVER 127.0.0.1 SOURCE_PORT_CLIENT1 TEST
Replace SOURCE_PORT_CLIENT1 with the source port displayed in your test.
line recieved on SERVER from 127.0.0.1 SOURCE_PORT_CLIENT1 : HELLO
on sockwrite on CLIENT CLIENT1, no error
on sockwrite on SERVER, no error
line recieved on CLIENT CLIENT1 from 127.0.0.1 8001 : WORLD
line recieved on SERVER from 127.0.0.1 SOURCE_PORT_CLIENT2 : HELLO
on sockwrite on CLIENT CLIENT2, no error
on sockwrite on SERVER, no error
line recieved on CLIENT CLIENT2 from 127.0.0.1 8001 : WORLD
on sockwrite on SERVER, no error
on sockclose error on SERVER: 3 - [10054] Connection reset by peer
So after closing the socket client-side, trying to send a packet to that client results in the server socket itself being closed, which is wrong, mIRC should eventually trigger on sockwrite with $sockerr set, but it should keep the socket (SERVER here) opened because there are others client 'connected' to it. In the actual configuration, You can still use /sockudp -kn SERVER 127.0.0.1
SOURCE_PORT_CLIENT2 TEST to communicate from the server to the client2, but client2 cannot send back a packet.