Click here to Skip to main content
15,894,955 members
Home / Discussions / C#
   

C#

 
AnswerRe: pattern for taking action based on stream of data Pin
Luc Pattyn2-Nov-09 7:59
sitebuilderLuc Pattyn2-Nov-09 7:59 
QuestionParsing Xml to SortedList with System.Xml.Linq Pin
thiago barbedo2-Nov-09 6:09
thiago barbedo2-Nov-09 6:09 
QuestionRLE (Run Length Encoding) in C# [modified] Pin
earlgraham2-Nov-09 5:54
earlgraham2-Nov-09 5:54 
GeneralRe: RLE (Run Length Encoding) in C# Pin
harold aptroot2-Nov-09 7:46
harold aptroot2-Nov-09 7:46 
GeneralRe: RLE (Run Length Encoding) in C# [modified] Pin
earlgraham2-Nov-09 8:31
earlgraham2-Nov-09 8:31 
GeneralRe: RLE (Run Length Encoding) in C# Pin
harold aptroot2-Nov-09 13:26
harold aptroot2-Nov-09 13:26 
AnswerRe: RLE (Run Length Encoding) in C# [modified] Pin
Oleg Orlov6-Jan-13 15:18
Oleg Orlov6-Jan-13 15:18 
QuestionUDP/TCP Port Forwarding [modified] Pin
Boss52-Nov-09 5:21
Boss52-Nov-09 5:21 
Hello all.

I'm feeling pretty confused about how the port forwarding is done. My situation is: I have Comp1 with a local IP (192.168.0.2) connected to Comp2 with external IP and internet connection, and some unknown Internet Client (IC), who needs to send data to the Server hosted at Comp1 through UDP port 7777 and then receive a response.

I managed to forward UDP data from Comp2 to Comp1 by simply accepting IC's packets at Comp2's port 7777 and sending them to Comp1's port 7777, but the problem is that Comp1's Server sees sender as Comp2 and sends response to it (192.168.0.1), rather than to IC.

So how do I forward IC's data from Comp2 to Comp1 with Comp1's Server knowing, that response must be sent to IC? I would also like to see the way it's done with TCP.



Here's what I managed to do:

namespace PortForwarder
{
    class Program
    {
        public static UdpClient UDP1 = new UdpClient(7777);

        static void Main(string[] args)
        {
            Console.Title = "Port Forwarder";
            Console.WriteLine("-= Port Forwarder started. =-");
            Console.WriteLine("UDP port 7777 forwarded");

            UDP1.BeginReceive(ReceiveDataUDP1, null);

            while (true) { };
        }

        static void ReceiveDataUDP1(IAsyncResult ar)
        {
            IPEndPoint IEP = new IPEndPoint(IPAddress.Any, 0);
            Byte[] receiveBytes = UDP1.EndReceive(ar, ref IEP);

	    // Trying to "lie" about local IEP results in exception
            // UdpClient US1 = new UdpClient(IEP);
            // US1.Send(receiveBytes, receiveBytes.Length, "192.168.0.2", 7777);

	    UDP1.Send(receiveBytes, receiveBytes.Length, "192.168.0.2", 7777);
            UDP1.BeginReceive(ReceiveDataUDP1, null);
        }
    }
}




P.S. If it wasn't obvious enough, Comp1 is connected to the internet through Comp2's ICS (Internet Connection Sharing). Comp2 is running Windows Server 2008 and connects to the internet through VPN connection. I tried to set up NAT there, but VPN connection cannot be shared for some reason (and sharing public adapter doesn't help). If, by any chance, anybody knows how it's configured, I would be glad. Smile | :)

modified on Monday, November 2, 2009 11:37 AM

AnswerRe: UDP/TCP Port Forwarding Pin
Jimmanuel2-Nov-09 8:00
Jimmanuel2-Nov-09 8:00 
GeneralRe: UDP/TCP Port Forwarding Pin
Boss52-Nov-09 8:12
Boss52-Nov-09 8:12 
GeneralRe: UDP/TCP Port Forwarding Pin
Jimmanuel2-Nov-09 8:25
Jimmanuel2-Nov-09 8:25 
GeneralRe: UDP/TCP Port Forwarding Pin
Boss52-Nov-09 8:53
Boss52-Nov-09 8:53 
GeneralRe: UDP/TCP Port Forwarding Pin
satthi113-Jan-10 0:11
satthi113-Jan-10 0:11 
GeneralRe: UDP/TCP Port Forwarding Pin
Jimmanuel13-Jan-10 2:50
Jimmanuel13-Jan-10 2:50 
QuestionC# MDI Forms layout [modified] Pin
FBCode2-Nov-09 4:28
FBCode2-Nov-09 4:28 
AnswerRe: C# MDI Forms layout Pin
Henry Minute2-Nov-09 5:56
Henry Minute2-Nov-09 5:56 
GeneralRe: C# MDI Forms layout [modified] Pin
FBCode2-Nov-09 21:13
FBCode2-Nov-09 21:13 
QuestionAccessing sound card Pin
Darren Shields2-Nov-09 4:22
Darren Shields2-Nov-09 4:22 
QuestionHow can I know/see on which core a thread run ? Pin
evyatar.v2-Nov-09 3:20
evyatar.v2-Nov-09 3:20 
AnswerRe: How can I know/see on which core a thread run ? Pin
Abhishek Sur2-Nov-09 3:25
professionalAbhishek Sur2-Nov-09 3:25 
GeneralRe: How can I know/see on which core a thread run ? Pin
harold aptroot2-Nov-09 3:50
harold aptroot2-Nov-09 3:50 
GeneralRe: How can I know/see on which core a thread run ? Pin
Abhishek Sur2-Nov-09 6:09
professionalAbhishek Sur2-Nov-09 6:09 
GeneralRe: How can I know/see on which core a thread run ? Pin
harold aptroot2-Nov-09 6:23
harold aptroot2-Nov-09 6:23 
GeneralRe: How can I know/see on which core a thread run ? Pin
Abhishek Sur2-Nov-09 20:23
professionalAbhishek Sur2-Nov-09 20:23 
AnswerRe: How can I know/see on which core a thread run ? Pin
Luc Pattyn2-Nov-09 3:34
sitebuilderLuc Pattyn2-Nov-09 3:34 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.