Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6540979
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:02:49+00:00 2026-05-25T11:02:49+00:00

I been trying to learn the TCP protocol. so I am able to transfer

  • 0

I been trying to learn the TCP protocol. so I am able to transfer data between two computers on the same network as:

\\the server:

var server = new TcpListener(ipAddress, port); //create a server
server.Start(); //start the server

//wait here until a client get's connected to this computer
TcpClient someClient = server.AcceptTcpClient();

NetworkStream stream = someClient.GetStream(); \\create a network stream object in order to read and send data to the other connected computer

once the server is running, the client application will be able to connect to the server as:

//Client:
var client = new TcpClient(serverIP, port);
NetworkStream stream = client.GetStream();
//initialize data to by some byte array. the data you wish to send
stream.Write(data, 0, data.Length);



byte[] bytes = new bytes[1000] //instantiate a byte array
connection.stream.Read(bytes, 0, bytes.Length)  // wait here until data is send 

// in this line data has been received and it will be placed the bytes array

I label each node with a different letter. for example note how computer A and computer C happen to be on the same network:

enter image description here

Hope this picture helps me explain what I mean.

Establish connection between computer A and C:

If I want to establish a connection between computer A and C then that will probably be the easiest case. In other words I will not have to do any kind of port forwarding in order to establish the connection.

Establish connection between computer A and server S:

if the client computer happens to be computer A and the server computer happens to be computer S then computer A will be able to find server S. So this connection should be simple too.

Establish connection between computer A and computer B: (here is my problem)

So if computer A wants to find computer B then router Y will have to forward all traffic from port ‘somePort P’ to computer B and A will have to provide the ip address of router Y or the WAN ip address.

Until this point my title question should not make sense let me explain what I mean when I say “Pass tcp connection to different computer”

I actually need to establish a connection between computer A and computer B without having to configure the routers. I been thinking a lot and I think this should be possible: (it’s a little crazy though)

if you remember from my previous code once the connection was established, everything that was send/written through the network stream is received by the other end of the connection. so because computer A is not able to connect to computer B then make A connect to the server S. So far there is a connection between computer A and server S. Ok now establish a tcp connection between computer B and server S. by now the server S should have two distinct tcp connections, one to computer A and the other to computer B.

Because the server has two distinct tcp connections it should have also two NetworkStream objects. let’s say that the tcp connection between server S and computer A has the object NetworkStream streamA; and the tcp connection with computer B has the object NetworkStream streamB;

So here comes the crazy part. The server S serializes the instantiated and working object streamB and sends that object to computer A. then computer A deserializes that object and cast it to a NetworkStream object. Computer A should now have a copy of object streamB. WHAT WILL HAPPEN IF THEN YOU SEND DATA THROUGH OUT THAT STREAM!? theorically computer B should receive the data I think. I mean maybe I will have to modify each package header information so that router Y treats those packages as if they where coming from Server S!

the reason why I want to do this is because I have created a server application and client application where it will sync files between two computers on a specific folder. a lot of times users using this program do not know how to enable port forwarding. I also know I may be able to solve this using what is called as “tcp puch holing” but I have not been able to find a working method on c#….

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T11:02:50+00:00Added an answer on May 25, 2026 at 11:02 am

    The method you have suggested won’t work. A and B are both sending traffic to S. No matter what S sends to A or B, A and B will still have their routers (X and Y) passing traffic only to S. What you want is, as you mentioned, NAT hole punching.

    The basic idea of NAT hole punching is to have A send traffic to B and B send traffic to A simultaneously. If done correctly, each router (X and Y) will think the packet from the other side is a reply to the packet it sent, and they will establish NAT entries allowing A and B to talk to each other directly. This is almost impossible to do for TCP, but can be done for UDP.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been trying to learn multi-threaded programming in C# and I am confused
I have been trying to learn how to add testing to existing code --
I have been trying to learn more about lambda expressions lately, and thought of
For the past few weeks, I've been trying to learn about just how email
I've been lately trying to learn more and generally test Java's serialization for both
I've been trying to learn Python, and while I'm enthusiastic about using closures in
I've been trying to learn about applets by studying the code for the Welcome
I've been trying to learn about Neural Networks for a while now, and I
I've been trying to learn about metaclasses in Python. I get the main idea,
I have been trying to learn Erlang and have been running into some problems

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.