我正在编写一个程序来接收来自VLC的视频流并转发它。我正在使用java。我创建了一个端口(1234),我使用UDP从vlc端口接收数据包。我想将数据包转发到另一个端口,以便我可以重新路由它。但不幸的是我无法转发它。接收部分工作正常。我怎么解决它。我的代码如下:
DatagramSocket clientSocket = new DatagramSocket(1234);
DatagramSocket sendSocket = new DatagramSocket(9999);
InetAddress IPAddress = InetAddress.getByName("localhost");
System.out.println("Connected to server !");
Thread.sleep(100);
int i=0;
byte[] recieveData = new byte[8196];
byte[] sendData= new byte[8196];
DatagramPacket dp=new DatagramPacket(recieveData,recieveData.length, IPAddress, 1234);
while(true)
{
clientSocket.receive(dp);
recieveData=dp.getData();
sendData=dp.getData();
System.out.println(recieveData.toString());
System.err.println("chunk no: "+i+" , chunk length: "+ dp.getLength() + ".----> --> forwarding");
i++;
DatagramPacket sendPacket=new DatagramPacket(sendData, dp.getLength(), IPAddress, 9999);
sendSocket.send(sendPacket);
}