Skip to Main Content

Java APIs

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

UDP questions - Datagram

807604Oct 31 2010 — edited Nov 1 2010
I've got the listener setup alright but only way i can get it to catch udp packets are by using "localhost" hostname if i use my global ip, i will never receive anything, i've checked my router and opened that port and all but i still can only receive packets when using "localhost"

public Boolean Send(byte[] data, String addr, int port)

    		DatagramPacket packet = new DatagramPacket(data, data.length, new InetSocketAddress(addr, port));
    		_socket.send(packet);
                _socket = new DatagramSocket(port);
                if (_socket.isBound()) {
                    byte[] _buffer = new byte[2048];
                    DatagramPacket packet = new DatagramPacket(_buffer, _buffer.length);
                    while (_socket.isBound()) {
                        _socket.receive(packet);
                        int length = packet.getLength();
                        byte[] data = new byte[length];
                        System.arraycopy(_buffer, 0, data, 0, length);
                        System.out.println(java.util.Arrays.toString(data));
                        packet.setLength(_buffer.length);
                    }
what am i doing wrong ?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 29 2010
Added on Oct 31 2010
2 comments
117 views