Hello.
I would like to make a network scanner, too.
I have this code: (I call this script in create event.)
tb_LAN=udp_bind(23535);
write_ushort(global.tb_BUFFER,1);
write_ubyte(global.tb_BUFFER,0);
udp_send(global.tb_BUFFER,filename_change_ext(mplay_ipaddress(),".255"),23535);
buffer_clear(global.tb_BUFFER);
The server's step event has got this script:
while(udp_receive(tb_LAN)) {
tb_Bytesize=socket_receivebuffer_size(tb_LAN);
while(tb_Bytesize>0) {
tb_Bytesize-=read_ushort(tb_LAN)+2;
tb_MessageType=read_ubyte(tb_LAN);
switch(tb_MessageType) {
case 0: //Lan üzenet
write_ushort(global.tb_BUFFER,11+string_length(global.tb_NAME));
write_ubyte(global.tb_BUFFER,1);
write_ushort(global.tb_BUFFER,string_length(global.tb_NAME));
write_string(global.tb_BUFFER,global.tb_NAME);
write_int(global.tb_BUFFER,global.tb_PORT);
write_ushort(global.tb_BUFFER,Get_Players_Count()); //Get_Players_Count(); how many player is active
write_ushort(global.tb_BUFFER,global.tb_PLAYERS[0,0]); //global.tb_PLAYERS[0,0]; ==10
udp_send(global.tb_BUFFER,socket_remote_ip(tb_LAN),23535);
buffer_clear(global.tb_BUFFER);
break;
default: //Ismeretlen üzenet
break;
}
}
}
End this script is in the client's step:
while(udp_receive(tb_LAN)) {
tb_Bytesize=socket_receivebuffer_size(tb_LAN);
while(tb_Bytesize>0) {
tb_Bytesize-=read_ushort(tb_LAN)+2;
tb_MessageType=read_ubyte(tb_LAN);
switch(tb_MessageType) {
case 1: //Lan üzenet
//return ip|játékos neve|port|játékosszám|max szám
return socket_remote_ip(tb_LAN)+"|"+read_string(tb_LAN,read_ushort(tb_LAN))+"|"+string(read_int(tb_LAN))+"|"+string(read_ushort(tb_LAN))+"|"+string(read_ushort(tb_LAN));
break;
default: //Ismeretlen üzenet
break;
}
}
}
If the server is running on ,,A" computer and the client is running on the ,,B" computer, the client will get the message.
But, if the server and the client is running on the same computer, the client doesn't recieve the UDP message
or if two clients are scanning only the first will get the message.
I think when the udp_send(buffer,xxx.xxx.x.255,12345) is start it will go until the message will send to an ip.
If it find an ip, it sends and the script is stop running.
And I have an other problem with UDP sending:
tb_LAN=udp_bind(12345);
write_ushort(tb_LAN,1);
write_ubyte(tb_LAN,1);
udp_send(tb_LAN,"xxx.xxx.x.xxxx",12345);
It doesn't send the message.
Can anybody help me?