mckooter Posted September 24, 2009 Share Posted September 24, 2009 Ive been working on this for a while, and i cannot determine if i am not connecting properly, or if the data im sending is wrong and thats why im not getting a response. The goal is to send data to a gaming server via udp, and recieve a response of server information. mainly i am looking to just see if the game server is running, and it will not respond to a regular tcp ping at its port, but the data it sends back could also be usefull too. here is the code i have so far: <?php $binary_msg = chr(0x00).chr(0x02).chr(0xF1).chr(0x26).chr(0x01).chr(0x26).chr(0xF0).chr(0x90).chr(0xA6).chr(0xF0).chr(0x26).chr(0x57).chr(0x4E).chr(0xAC).chr(0xA0).chr(0xEC).chr(0xF8).chr(0x68).chr(0xE4).chr(0x8D).chr(0x21); $fp = fsockopen("udp://<<ipaddresshere>>",2302,$errno,$errstr); if (!$fp) { echo "ERROR: $errno - $errstr<br />\n"; } else { fwrite($fp, $binary_msg); echo fread($fp, 26); fclose($fp); } ?> the server was not doing anything at this point, through some help i recieved elsewhere i tried this: var_dump(bin2hex(fread($fp, 26))); and the response was different depending on if i ran it as php4 or php5 (i have to put .php5 on the file to force it myself) PHP5: Warning: fread(): 1 is not a valid stream resource in /homepages/14/d187646903/htdocs/sites/tekagis/port.php5 on line 12 string(0) "" PHP4: string(0) "" so I assume that its working, but im not getting any response from the server, is that right? or am i missing something, and if the code is right, can anyone see why it might not be responding, the data i am sending was gathered from this script that does work (C# i believe): Socket s = new Socket(lep.Address.AddressFamily, SocketType.Dgram, ProtocolType.Udp); byte[] inputToBeSent = new byte[21]; // Create the "special" packet that will return the correct data inputToBeSent[0] = 0x00; inputToBeSent[1] = 0x02; inputToBeSent[2] = 0xF1; inputToBeSent[3] = 0x26; inputToBeSent[4] = 0x01; inputToBeSent[5] = 0x26; inputToBeSent[6] = 0xF0; inputToBeSent[7] = 0x90; inputToBeSent[8] = 0xA6; inputToBeSent[9] = 0xF0; inputToBeSent[10] = 0x26; inputToBeSent[11] = 0x57; inputToBeSent[12] = 0x4E; inputToBeSent[13] = 0xAC; inputToBeSent[14] = 0xA0; inputToBeSent[15] = 0xEC; inputToBeSent[16] = 0xF8; inputToBeSent[17] = 0x68; inputToBeSent[18] = 0xE4; inputToBeSent[19] = 0x8D; inputToBeSent[20] = 0x21; try { DateTime dtStart = DateTime.Now; // Sends datagram to the IpEndPoint specified. This call blocks. s.SendTo(inputToBeSent, 0, inputToBeSent.Length, SocketFlags.None, lep); // Creates an IpEndPoint to capture the identity of the sending host. IPEndPoint sender = new IPEndPoint(IPAddress.Any, 0); EndPoint tempRemoteEP = (EndPoint)sender; // Creates a byte buffer to receive the message. int iAvailable = s.Available; int iSecCount = 0; Link to comment https://forums.phpfreaks.com/topic/175370-sending-and-recieving-data-to-udp-port/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.