473,797 Members | 2,893 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

C# Socket Communication Behind a router

80 New Member
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 10742
Plater
7,872 Recognized Expert Expert
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
cnixuser
80 New Member
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 Recognized Expert Expert
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
cnixuser
80 New Member
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 Recognized Expert Expert
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
cnixuser
80 New Member
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:1200 0).

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 Recognized Expert Expert
that sounds about right.
Jul 31 '08 #8
cnixuser
80 New Member
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 New Member
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(outcomin g 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(incomin g) 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
1177
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
4240
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 indirrectly connected to internet. To elaborate it further, suppose there is a computer on my office LAN running my application. This computer is connected to internet through our Proxy server. Now any other computer which is also on LAN and is...
4
2352
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
1520
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# devs at our company can just drop in and use (it's an event and message passing system.) I'm sure, as most things C#/.Net, it's relatively simple, but if I can discover some caveats the easy way rather than the hard way I'm always up for that...
5
15104
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 one management console/monitor that receives messages and keeps track of keep-alive polling. The monitor created a new WinSock connection for each client that logged on. These were put into an array of controls. I'm sure this can also be done with...
8
5696
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 communication. It will be called by a multithreaded server application to send some data to an another server ( which is a linux server ).
1
1380
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 fine) Now, i want this client app to be able to connect to my server from outside the lan as well... Like i would like to give my user the ability to connect to my
8
4584
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 via serial port and serial/ethernet converter (MOXA NE-4100T) with TCP server. So communication is in that way: MyApplication(TCP client)-----------------(TCPServer)MOXA(serial)---(serial)LED Display
13
2734
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 exchange info with the web server. I don't familarize with C# programming and here I just want to know is that possible to implemented?
0
9536
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10468
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10245
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10021
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9063
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7559
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6802
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5582
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2933
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.