I've created a client which sends the get server list command, but the received bytes isn't readable.
Here is my code :
byte[] receiveBytes = udp.Receive(ref RemoteIpEndPoint);
string[] returnData = Encoding.Default.GetString(udp.Receive(ref RemoteIpEndPoint)).Split('\\');
textBox1.Lines = returnData;
in locals i see the write value
but program show me this
can someone tell me what is wrong with my code ?
ok i change my code to
yte[] receiveBytes = udp.Receive(ref RemoteIpEndPoint);
int size = receiveBytes.Length;
int i = 0;
while ( i <= size-5 )
{
string ip = receiveBytes[i] + "." + receiveBytes[i + 1] + "." + receiveBytes[i + 2] + "." + receiveBytes[i + 3] ;
int port = receiveBytes[i + 4] * 256 + receiveBytes[i + 5];
textBox1.Text += ip + ":" + port.ToString() + Environment.NewLine;
i = i + 6;
}
but received data isnt right !
i find smiler code on php and its working .
$data = explode("\\", $data);
for($i=0, $o=0; $i<count($data); $i++) {
if (strlen($data[$i])>=4) { //fix
// First 4 bytes are the ip:
$list_server[$o]['ip']=ord($data[$i][0]).".".ord($data[$i][1]).".".ord($data[$i][2]).".".ord($data[$i][3]);
// Last 2 bytes are the port, Takes penultimate number and multiply by 256 and sum with the last number:
$list_server[$o]['port']=(ord($data[$i][4])*256) + ord($data[$i][5]);
//GetName($list_server[$o]['ip'],$list_server[$o]['port']);
$o++;
}
}
i cant guess what is wrong with my code .