The PC Windows is sending the confirmation. But that is not arriving to Linux.
What am i missing? (But when i do not use Windows 7 and do the same code under Linux to Linux it works.)
Any ideas!!!
Windows 7 PC: Sender/Replyer
System.out.println("[UDP]: "
+ "RemoteIP: " + IPAddress.toString() + " "
+ "Port: " + port + " "
+ "Length: " + send.length() + " "
+ "Sending confirmation!"); // it shows it has correct ip, port and lenght
sockOutput = new DatagramPacket(send.getBytes(), send.length(), IPAddress, port);
serverSock.send(sockOutput);// is it failing???
Linux PC: Receiver/Commander
String receive = sendUDPBytes("request", ip).toString();
if (receive.length()<=0) // Waiting forever, and nothing happens LINUX.
{
System.out.println("FAILED");
System.exit(0);
} else {
try {
/* JOB todo */
} catch (Exception ex) {
}
}
sockOutput.write(receive.getBytes());
public static String sendUDPBytes(String bytes, String[] ip) throws IOException
{
String downloaded = null;
DatagramSocket socket = new DatagramSocket();
InetAddress IPAddress = InetAddress.getByName(ip[2]);
byte[] sendData = new byte[14024];
byte[] receiveData = new byte[14024];
sendData = bytes.getBytes();
DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length);
socket.connect(IPAddress, 58889);
if (socket.isConnected())
{
System.out.println("[UDP]: sending....., waiting......... until receive....");
socket.send(sendPacket);
}
DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length);
socket.receive(receivePacket);
downloaded = new String(receivePacket.getData());
System.out.println("[UDP]: closing.....");
socket.close();
return downloaded;
}
Follow up:
0) Do not get confuse with “ARE U IN A SAME SUBSET???”, so if you have /28 network all in can exchange the packet. In that case it works but that is not the case most of the time.
1) The code is perfect, when i test LAN to LAN no matter what operating system it is, it works (no firewall ofcource)
2) When i test Windows to Windows in the same PC it works too
3) When i test Linux to Linux it works too
4) When i test Linux to Windows or Windows to Linux it works too
5) The same code i put in one central server and same code i ran in local Windows PC, and other ISP seems to allow it.
6) Sp-ended 10 hours to find it
Guess:
What exactly was then the cause? Well, ISP is losing the packet that was sent to my public IP or they maybe disabling those even i have Public IP.
You are doing
String bytesandgetBytes()depends on the platform encoding.getBytes("UTF-8")would be explicit.Another thing are the differing newlines: Linux \n, Windows \r\n.
The
toString()might throw an exception if the bytes stem from Windows Latin-1 (Cp1252), and it tries to interprete them as UTF-8.