|
-
Nov 30th, 2008, 06:00 AM
#1
Thread Starter
New Member
Forward incoming UDP packets
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:
Code:
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:
Code:
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.
-
Nov 30th, 2008, 09:26 AM
#2
Re: Forward incoming UDP packets
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:
VB.NET Code:
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.
-
Dec 1st, 2008, 02:49 AM
#3
Thread Starter
New Member
Re: Forward incoming UDP packets
Ah, the answers are always so simple.
Cheers, that worked perfectly.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|