PDA

Click to See Complete Forum and Search --> : Forward incoming UDP packets


Prophet][
Nov 30th, 2008, 05:00 AM
I'm trying to find a simple way take an incoming video stream over UDP and forward it onto another ip address. I don't want to decode the video or view it for anything. I just want a program that accepts the packets and passes them onto another computer on different port. Effectivly a router I guess.

So far I have been using the System.Net.Sockets to try the following code

Declerations:


Public receivingUdpClient As UdpClient
Public RemoteIpEndPoint As New System.Net.IPEndPoint(System.Net.IPAddress.Any, 0)
Dim udpClient As New UdpClient
Dim OutputIP As System.Net.IPAddress = System.Net.IPAddress.Parse("127.0.0.1")
Dim OutputPort As Integer = 1250
Dim InputPort As Integer = 1234



Sub:

udpClient.Connect(OutputIP, OutputPort)
receivingUdpClient = New System.Net.Sockets.UdpClient(InputPort)
udpClient.Send(receivingUdpClient.Receive(RemoteIpEndPoint), 0)



I am aware I'm sending it onto the same computer, I'm only doing it for now for testing purposes. I know this will need to run in a separate thread so that the program doesn't hang waiting for it to finish (which it never will)

I'm being a bit ambishous puting the receive code into the send method. What would be the best way to do this? Use 2 threads, one for receive and one for send? Save it to a buffer?

Any help would be awsome as network stuff is not my thing.

Atheist
Nov 30th, 2008, 08:26 AM
In the send call, you're specifying 0 as the second argument, when it should be the number of bytes you want to send. What you'd need to do is something like this:

Dim dgram() As Bytes = receivingUdpClient.Receive(RemoteIpEndPoint)
udpClient.Send(dgram, dgram.Length)

Use 1 thread for both the reading and the writing, cant see any advantage to use 2 threads in this case.

Prophet][
Dec 1st, 2008, 01:49 AM
Ah, the answers are always so simple.

Cheers, that worked perfectly.