我试图在 23000 上保留一个监听 UDP 端口,该应用程序在本地环境中运行良好。但是切换到3G没有机会,流量被阻塞。
我尝试在接收之前“打开”在同一端口上发送 4 字节数据的运营商通道:
InetAddress serverAddr = InetAddress.getByName(SOULISSIP);
DatagramChannel channel = DatagramChannel.open();
socket = channel.socket();
//socket = new DatagramSocket();
socket.setReuseAddress(true);
//InetSocketAddress ia = new InetSocketAddress("localhost", SERVERPORT);
InetSocketAddress sa = new InetSocketAddress(SERVERPORT);
socket.bind(sa);
DatagramPacket holepunh = new DatagramPacket(new byte[]{0,1,2,3},4, serverAddr, SERVERPORT);
socket.send(holepunh);
// create a buffer to copy packet contents into
byte[] buf = new byte[200];
// create a packet to receive
DatagramPacket packet = new DatagramPacket(buf, buf.length);
Log.d("UDP", "***Waiting on packet!");
socket.setSoTimeout((int) opzioni.getDataServiceInterval());
// wait to receive the packet
socket.receive(packet);
UDPSoulissDecoder.decodevNet(packet);
socket.close();
有没有一种简单的方法可以打开通道并在端口 23000 上接收 UDP 数据报?