473,320 Members | 1,950 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

C# Socket Communication Behind a router

Hi,

I was wondering if someone could give me some general pointers about creating client server applications that would be able to communicate with each other over not just the LAN which I am able to do, but would be able to communicate with each other and exchange filestreams over the internet, meaning in most cases communication with PC's behind a router and / or a gateway server. I have applications that can send messages to each other and send filestreams to each other via socket ;however, these applications only take into account the IP address of the client and server applications and the port the socket is on, so I assume that I need to use the external IP of the router the application is behind and a port number on that connection perhaps? Can someone please point me in the right direction and tell me what I need to be trying to do (provide terms usable for a good google search, sample code, your own explanation) so that I can communicate with applications over the internet behind a router?

Thanks in advance!
Jul 30 '08 #1
9 10692
Plater
7,872 Expert 4TB
If a router is programmed to allow traffic through a port (i.e. opened up a port to a specfic computer insde it's network) you should be able to communicate through it.

Example:

I have a server behind a firewall. My software listens on port 9088. I tell my router that any incomming traffic for port 9088 should be directed to my server.
Suppose the outside IP address for my router is 64.64.64.20

You are behind a firewall, and have a copy of my client software. You would put in to connect to 64.64.64.20 on port 9088 and even though you are behind a firewall (this is only true on MOST routers for home use) your connection will go out and connect to me.

Firewalls generally only stop traffic from getting in, not traffic going out.
Jul 30 '08 #2
If a router is programmed to allow traffic through a port (i.e. opened up a port to a specfic computer insde it's network) you should be able to communicate through it.

Example:

I have a server behind a firewall. My software listens on port 9088. I tell my router that any incomming traffic for port 9088 should be directed to my server.
Suppose the outside IP address for my router is 64.64.64.20

You are behind a firewall, and have a copy of my client software. You would put in to connect to 64.64.64.20 on port 9088 and even though you are behind a firewall (this is only true on MOST routers for home use) your connection will go out and connect to me.

Firewalls generally only stop traffic from getting in, not traffic going out.

Thanks for your reply,

Since I am able to use instant messenger clients and have web pages displayed on the PC I am currently using which is behind my company's router / gateway server, would it be safe to say that port forwarding is already enabled, and that all I would have to ask IT to do is enable port forwarding for a new port that a specify for my application?
Jul 30 '08 #3
Plater
7,872 Expert 4TB
All of those program you named are all "client" programs, they send requests OUT through the firewall. None are indicitive of port forwarding.
You could request a port be opened up for you, but they are going to want a good reason for doing so.
Jul 31 '08 #4
All of those program you named are all "client" programs, they send requests OUT through the firewall. None are indicitive of port forwarding.
You could request a port be opened up for you, but they are going to want a good reason for doing so.
But don't the client applications need to be able to listen on a specific port for messages incoming from the server?
Jul 31 '08 #5
Plater
7,872 Expert 4TB
But don't the client applications need to be able to listen on a specific port for messages incoming from the server?
No. The server listens for connections, the client sends out a request to connect to it. A connection is established and communication occurs back and forth on that one connection.
Jul 31 '08 #6
No. The server listens for connections, the client sends out a request to connect to it. A connection is established and communication occurs back and forth on that one connection.
Ok, let me see if I can articulate properly what you are trying to convey here to verify that I am understanding you correctly:

Server Application -- Behind a router / gateway server with say port 12,000 opened on the external IP

Client application -- Uses any open port on the router / gateway server it is behind, gets a connection by sending to the external IP address of the router the Server Application's PC is behind at port 12,000 (11.22.1.1:12000).

The connection is established and all communication and filestream exchange between the 2 applications occurs and the server sends to the port on the external IP of the router the client pc is behind.

Is this the basic gist of what you mean? Thanks again for the continued assistance :)
Jul 31 '08 #7
Plater
7,872 Expert 4TB
that sounds about right.
Jul 31 '08 #8
that sounds about right.

I believe this conversation will prove to be very fruitful, thank you for your assistance.
Jul 31 '08 #9
Svinja
25
You need to forward ports only for the server(incoming connection).
Client does not need to forward port because of the way NAT in your router works.

When client(outcoming connection) start the connection, it sends some packets over the router, NAT(in the router) remembers clients IP and port and puts it in temporary table. That way when packets(incoming) come for client, the router knows on which IP to send it because of the temporary tables.

Hope you got it. If you need some better explanation, google NAT.
Jul 31 '08 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Jacoste | last post by:
Using Socket communication under Terminal Services. Are there some kind of "virtual sockets", so that my app. can use the same port for different users on the same Terminal Server? /Jacoste
2
by: Yassar | last post by:
I want my P2P application to works well even when users are behind proxy or LAN. i.e Two instance of my application should be able to communicate even if they are on different LANs but...
4
by: Sa¹o Zagoranski | last post by:
Hi! I'm writing a simple 3D First person shooter game. It is a multiplayer game, where all the players connect to one server.
2
by: WTH | last post by:
with a C# client (and/or server, but server not important)? I've got a scalable high speed (uses completion ports) C++ TCP/IP communication server but I'd like to write a C# client that other C#...
5
by: Rotzooi | last post by:
Hi, In the past I created a VB6 application that was capable of accepting multiple client connections for status logging over the internet using simple non-Windows clients (GSM/GPRS). There is...
8
by: Roodie | last post by:
Hello, I have a quite specific problem, and after half a day spent with Google, still no solid answer. The task: I have to write a C# class Library ( DLL ) to handle TCP socket...
1
by: batista | last post by:
Hi, My problem is that i have a client which was, uptil now, running inside a lan and using sokcet communication to connect to server which is also insdie the same lan.....(it was all working...
8
by: panko | last post by:
Hello, I can't manage with asynchronous socket communication. :( I wrote a class CSocket.cs. This class is taking care of sending strings to LED display. This display is actually communicating...
13
by: Wade Yin | last post by:
Hi, If I can write a ActiveX component that can support socket communication in webpage, that will make browser have strongger capability to communicate with different clients, but not only can...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.