Results 1 to 3 of 3

Thread: Forward incoming UDP packets

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2008
    Posts
    2

    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.

  2. #2
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    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:
    1. Dim dgram() As Bytes = receivingUdpClient.Receive(RemoteIpEndPoint)
    2. 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.
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  3. #3

    Thread Starter
    New Member
    Join Date
    Nov 2008
    Posts
    2

    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
  •  



Click Here to Expand Forum to Full Width