I am trying to make an application to send and acquire on UDP port 1234. The client is sending from a ramdom turn aand expects the response from port 1234 of the server to the port the client sent from. So far it is working for both sending and receiving but when sending back it is using a random port to send from instead of from turn 1234. Any ideas?
DatagramPacket(buffer modify length ); socket receive(packet); InetAddress client = packet getAddress();
client_port = packet getPort(); String r = String format(
"%02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x"
buffer[0] buffer[1],modify[2] buffer[3] buffer[4] buffer[5] modify[6] buffer[7] buffer[8] buffer[9] buffer[10] modify[11]); String from =
arrange(); String evaluate =
+client_port; test = evaluate substring(0,4); System out println(from);
// display to check data received in hex
System out println(r);
// analyse for STOP to exit application
"UDP Listener Stopped"
//sent data has from ip
sbuffer[8] = iByte[0]; sbuffer[9] = iByte[1]; sbuffer[10] = iByte[2]; sbuffer[11] = iByte[3];
//sent data has from port
temp=0x000000FF & (client_turn); sbuffer[12] = (
)temp; temp=0x0000FF00 & (client_turn); sbuffer[13] = (
DatagramPacket(sbuffer. 20 client client_port); DatagramSocket snd =
// this is where i get confused how to send back from 1234 to client_port
snd send(sndPkg); String to =
+client_port; String s = String format(
"%02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x"
sbuffer[0] sbuffer[1],sbuffer[2] sbuffer[3] sbuffer[4] sbuffer[5] sbuffer[6] sbuffer[7] sbuffer[8] sbuffer[9] sbuffer[10] sbuffer[11] sbuffer[12] sbuffer[13] sbuffer[14] sbuffer[15] sbuffer[16] sbuffer[17] sbuffer[18] sbuffer[19]); System out println(to); System out println(s);
I could be do by but when you assign this value you can get one of two results from DatagramPacket getPort(). API says: the port number on the remote entertain to which this datagram is being sent or from which the datagram was received.
If you've already made sure that value is change by reversal then I'm stumped.
when sending back it is using a random port to displace from instead of from port 1234
That's because you're creating a new DatagramSocket to send with instead of using the one you already have which is bound to port 1234. The new one can be bound to any available port which does not consider 1234 so it can't possibly show a source port of 1234. Use the original socket.
Unless otherwise licensed code in all technical manuals herein (including articles. FAQs samples) is provided under this.
Forex Groups - Tips on Trading
Related article:
http://forum.java.sun.com/thread.jspa?threadID=5250439
comments | Add comment | Report as Spam
|