I have made a simple program to send and receive a packet from a SA:MP server, which contains information about the specified server. This works correctly when I send the packet with a program called "Packet Sender", but my Java program just doesn't want to work. This is the code I am currently using:
DatagramSocket dataSocket = new DatagramSocket(iPort);
dataSocket.setSoTimeout(iTimeout);
byte[] bytepacket = szPacket.getBytes(Charset.forName("UTF-8"));
byte[] buf = new byte[256];
DatagramPacket recpacket = new DatagramPacket(buf, buf.length);
DatagramPacket packet = new DatagramPacket(bytepacket, bytepacket.length, address, iPort);
packet.setData(bytepacket);
packet.setAddress(address);
packet.setPort(iPort);
dataSocket.connect(address, iPort);
socketConnected = true;
System.out.println("Local port: " + dataSocket.getLocalPort());
System.out.println("Local IP: " + dataSocket.getLocalAddress());
System.out.println("Remote port: " + dataSocket.getPort());
System.out.println("Remote IP: " + dataSocket.getInetAddress());
System.out.println("Recieve Timeout: "+iTimeout+" milliseconds.");
dataSocket.send(packet);
System.out.println("Sent packet: "+ packet.getData());
dataSocket.receive(recpacket);
String recieved = new String(recpacket.getData(), 0, recpacket.getLength());
System.out.println("Recieved packet: "+ recieved);
dataSocket.close();
dataSocket.disconnect();
This is my debug:
Packet: SAMPÀßµai
Local port: 7777
Local IP: /192.168.0.103
Remote port: 7777
Remote IP: samp.lawlessrp.com/192.223.24.181
Recieve Timeout: 5000 milliseconds.
Sent packet: [B@76dd3333
java.net.SocketTimeoutException: Receive timed out
at java.net.DualStackPlainDatagramSocketImpl.socketReceiveOrPeekData(Native Method)
at java.net.DualStackPlainDatagramSocketImpl.receive0(Unknown Source)
at java.net.AbstractPlainDatagramSocketImpl.receive(Unknown Source)
at java.net.DatagramSocket.receive(Unknown Source)
at lillyramcharan.blacksirrah239.tracker.main.<init>(main.java:199)
at lillyramcharan.blacksirrah239.tracker.launch.init(launch.java:17)
at sun.applet.AppletPanel.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
In the debug "Packet" is the packet before it is converted into bytes. It is also missing one character due to it being an invalid ascii character (represented as CANCEL).
Here is a screenshot of the program I mentioned earlier, sending and returning the packet: http://puu.sh/6gRd5.png
EDIT: I have already tried disabling my firewall/allowing javaw (it is an applet) through my firewall, as well as packets with the port 7777 and 55056.
Any help would be appreciated! Thanks