mIRC Home    About    Download    Register    News    Help

Print Thread
#272392 30/01/24 09:07 PM
Joined: Feb 2023
Posts: 3
S
sadlol Offline OP
Self-satisfied door
OP Offline
Self-satisfied door
S
Joined: Feb 2023
Posts: 3
I am trying to do something like this in order to open a server that can receive UPD text messages sent from another application. Where am I wrong? Because in the test I do, nothing happens


on *:udpread:test:{
if ($sockerr) { echo -s An error occured while trying to read data: $sock($sockname).wsmsg | return }
else {
sockread %a
echo -s rcvd: %a
}
}



alias start_udp_listener {
var %udpPort = 12345
sockudp -k test 127.0.0.1 %udpPort
echo -s UDP Server is listening on port %udpPort ...
}


/sockudp -t test 127.0.0.1 12345 hello

sadlol #272393 31/01/24 07:38 AM
Joined: Jul 2006
Posts: 4,180
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,180
Hello, you're using /sockudp to send a packet without the -n switch, which won't add a $crlf at the end of the packet.
In your reading, when you do /sockread %a, this will only read a terminated line (ending with $crlf or $lf), if the line doesn't end with a $crlf or $lf, /sockread %a will read nothing.
You should always make sure data has been read with $sockbr.
You can force a read of whatever is in the received buffer by using the -f switch in /sockread, i'll show the line by line method:

on *:udpread:test:{
if ($sockerr) { echo -s An error occured while trying to read data: $sock($sockname).wsmsg | return }
else {
var %a
sockread %a
;if sockread isn't reading a line, we return
if ($!sockbr) return
echo -s rcvd: %a
}
}

alias start_udp_listener {
var %udpPort = 12345
sockudp -k test 127.0.0.1 %udpPort
echo -s UDP Server is listening on port %udpPort ...
}
/sockudp -tn test 127.0.0.1 12345 hello

Also, you're using the same socket name to create the listening server and a client, not too sure about that, you might want to use a different socket name when trying to send a packet


#mircscripting @ irc.swiftirc.net == the best mIRC help channel

Link Copied to Clipboard