473,378 Members | 1,370 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,378 software developers and data experts.

C# and networking

I found a useful client/server combination for newbies at
http://www.msdnaa.net/Resources/Display.aspx?ResID=1375

I typed both of the programs and I ran them on one of my 2 computers (I have
a desktop and a laptop PC).

Then I copied the client program to the laptop, connected the laptop to my
PC, and I changed the following line:

TcpClient tcpClient = new TcpClient ("localhost", 4444);

to:

TcpClient tcpClient = new TcpClient(myIP, 4444);

(in which myIP is the IP address of my computer, that is displayed if you
typed "ipconfig" at the command prompt).

This all worked fine! I had to disconnect my computer from the Internet
(since I have a cable modem).

Now my question. Imagine the following situation:
- A friend of mine runs the server side program on his computer and gives me
his IP address;
- Both he and I connect our computers to the Internet (both he and I have
cable modems);
- I change the above statement (in the cliend side program) to:

TcpClient tcpClient = new TcpClient(MyFriendsIP, 4444);

- I run the client side program.

Will the communication still work?

I am still a network newbie but my first few steps were successful.

Will this also work with a router and two computers connected to it?

Hans Kamp.
Nov 15 '05 #1
7 1531
inline
"Hans Kamp" <in**@hanskamp.com> wrote in message
news:b3*************************@posting.google.co m...
I found a useful client/server combination for newbies at
http://www.msdnaa.net/Resources/Display.aspx?ResID=1375

I typed both of the programs and I ran them on one of my 2 computers (I have a desktop and a laptop PC).

Then I copied the client program to the laptop, connected the laptop to my
PC, and I changed the following line:

TcpClient tcpClient = new TcpClient ("localhost", 4444);

to:

TcpClient tcpClient = new TcpClient(myIP, 4444);

(in which myIP is the IP address of my computer, that is displayed if you
typed "ipconfig" at the command prompt).

This all worked fine! I had to disconnect my computer from the Internet
(since I have a cable modem).

I don't see why you had to disconnect from the internet...
Now my question. Imagine the following situation:
- A friend of mine runs the server side program on his computer and gives me his IP address;
- Both he and I connect our computers to the Internet (both he and I have
cable modems);
- I change the above statement (in the cliend side program) to:

TcpClient tcpClient = new TcpClient(MyFriendsIP, 4444);

- I run the client side program.

Will the communication still work?

Assuming there are no interdicting problems, such as firewalls, it should.
I am still a network newbie but my first few steps were successful.

Will this also work with a router and two computers connected to it?
It should on a cable\dsl router. But, depending on the router, it is
possible it won't (sorry to be complex, but it is a area with alot of
maybe's).

Hans Kamp.

Nov 15 '05 #2
"Daniel O'Connell" <on******@comcast.net> wrote in message
news:BNX5b.361356$Ho3.54072@sccrnsc03...
inline
"Hans Kamp" <in**@hanskamp.com> wrote in message
news:b3*************************@posting.google.co m...


I am still a network newbie but my first few steps were successful.

Will this also work with a router and two computers connected to it?


It should on a cable\dsl router. But, depending on the router, it is
possible it won't (sorry to be complex, but it is a area with alot of
maybe's).


Just make sure the router that the server is behind has port 4444 (or
whatever you are using) open and pointed to your server pc. The client's
router shouldn't need any special setup at all (since outgoing connections
are generally enabled, unless your friend setup some sort of special
firewall filtering, or is working behind a corporate firewall).

--
Mike Mayer
http://www.mag37.com/csharp/
mi**@mag37.com
Nov 15 '05 #3

"Michael Mayer" <mi**@mag37.com> schreef in bericht
news:%2****************@tk2msftngp13.phx.gbl...
"Daniel O'Connell" <on******@comcast.net> wrote in message
news:BNX5b.361356$Ho3.54072@sccrnsc03...
inline
"Hans Kamp" <in**@hanskamp.com> wrote in message
news:b3*************************@posting.google.co m...


I am still a network newbie but my first few steps were successful.

Will this also work with a router and two computers connected to it?


It should on a cable\dsl router. But, depending on the router, it is
possible it won't (sorry to be complex, but it is a area with alot of
maybe's).


Just make sure the router that the server is behind has port 4444 (or
whatever you are using) open and pointed to your server pc. The client's
router shouldn't need any special setup at all (since outgoing connections
are generally enabled, unless your friend setup some sort of special
firewall filtering, or is working behind a corporate firewall).


In that latter case, how does the outside world (or my friend) know the IP
address of the server computer?

Hans Kamp.
Nov 15 '05 #4
"Hans Kamp" <in**@hanskamp.com> wrote in message
news:bj**********@news4.tilbu1.nb.home.nl...

Just make sure the router that the server is behind has port 4444 (or
whatever you are using) open and pointed to your server pc. The client's
router shouldn't need any special setup at all (since outgoing connections are generally enabled, unless your friend setup some sort of special
firewall filtering, or is working behind a corporate firewall).


In that latter case, how does the outside world (or my friend) know the IP
address of the server computer?


I'm assuming that by router you mean a (~$100) box by Linksys, Netgear, SMC,
etc that is doing internet sharing through NAT (network address
translation). In this case, your server computer's IP address never shows
up on the internet. Instead, you want the IP address of the router itself.

Visit this page from your server:
http://www.whatismyip.com/

You'll find out that the ip address they report is most likely not the one
your server thinks it is (your server probably has a private domain address
such as 10.x.x.x or 192.168.x.x ). What's happenning is the router is
translating the private ip addresses from your server and laptop (and any
other computers behind the router) into one public ip address that was given
to you by your ISP (cable modem company, DSL provider, etc). The address
reported above (by whatismyip.com) is the one your friend needs. This is
the one that your router responds to, and then (assuming you've forwarded
the necessary port) the router will forward the connection to your server.

Note, if you have a dynamic address (changes periodically, like every day,
every week, etc) you might want to look into a dynamic dns provider such as
www.changeip.com ( i use these guys). You can setup a domain name to always
point to the latest IP address you got. I use them with my domain. They
have some free domains you can use, as well.

--
Mike Mayer
http://www.mag37.com/csharp/
mi**@mag37.com

Nov 15 '05 #5
"Michael Mayer" <mi**@mag37.com> wrote in message news:<es**************@TK2MSFTNGP11.phx.gbl>...
"Hans Kamp" <in**@hanskamp.com> wrote in message
news:bj**********@news4.tilbu1.nb.home.nl...

Just make sure the router that the server is behind has port 4444 (or
whatever you are using) open and pointed to your server pc. The client's
router shouldn't need any special setup at all (since outgoing connections are generally enabled, unless your friend setup some sort of special
firewall filtering, or is working behind a corporate firewall).
In that latter case, how does the outside world (or my friend) know the IP
address of the server computer?


I'm assuming that by router you mean a (~$100) box by Linksys, Netgear, SMC,
etc that is doing internet sharing through NAT (network address
translation). In this case, your server computer's IP address never shows
up on the internet. Instead, you want the IP address of the router itself.

Visit this page from your server:
http://www.whatismyip.com/


This URL gives the same result on both computers.
You'll find out that the ip address they report is most likely not the one
your server thinks it is (your server probably has a private domain address
such as 10.x.x.x or 192.168.x.x ). What's happenning is the router is
translating the private ip addresses from your server and laptop (and any
other computers behind the router) into one public ip address that was given
to you by your ISP (cable modem company, DSL provider, etc). The address
reported above (by whatismyip.com) is the one your friend needs. This is
the one that your router responds to, and then (assuming you've forwarded
the necessary port) the router will forward the connection to your server.


Yes, but it isn't clear what is the right PC, when both my laptop and
my PC show the same address.

Hans Kamp.
Nov 15 '05 #6

"Hans Kamp" <in**@hanskamp.com> schreef in bericht
news:b3**************************@posting.google.c om...
"Michael Mayer" <mi**@mag37.com> wrote in message news:<es**************@TK2MSFTNGP11.phx.gbl>...
"Hans Kamp" <in**@hanskamp.com> wrote in message
news:bj**********@news4.tilbu1.nb.home.nl...

Just make sure the router that the server is behind has port 4444 (or
> whatever you are using) open and pointed to your server pc. The client's > router shouldn't need any special setup at all (since outgoing

connections
> are generally enabled, unless your friend setup some sort of special
> firewall filtering, or is working behind a corporate firewall).

In that latter case, how does the outside world (or my friend) know the IP address of the server computer?


I'm assuming that by router you mean a (~$100) box by Linksys, Netgear, SMC, etc that is doing internet sharing through NAT (network address
translation). In this case, your server computer's IP address never shows up on the internet. Instead, you want the IP address of the router itself.
Visit this page from your server:
http://www.whatismyip.com/


This URL gives the same result on both computers.
You'll find out that the ip address they report is most likely not the one your server thinks it is (your server probably has a private domain address such as 10.x.x.x or 192.168.x.x ). What's happenning is the router is
translating the private ip addresses from your server and laptop (and any other computers behind the router) into one public ip address that was given to you by your ISP (cable modem company, DSL provider, etc). The address reported above (by whatismyip.com) is the one your friend needs. This is the one that your router responds to, and then (assuming you've forwarded the necessary port) the router will forward the connection to your

server.
Yes, but it isn't clear what is the right PC, when both my laptop and
my PC show the same address.


I found a solution in a different way. I can configure my router by using
"Virtual Servers" (with the Sitecom DC-202 that is
http://192.168.0.1/vs.htm) in which I can type the ports that must be
forwarded and the computer (in the format <ComputerName> (<IP>)
<KindOfConnection> in the combobox). In my case I must give a new name for
my program, giving 4444 as the Internal Port No. and as the External Port
No.

It should be both possible for servers like WinMX, a webserver, a telnet
server, an e-mail and a FTP server, and for the little servers you write
with C#.

Hans Kamp.
Hans Kamp.
Nov 15 '05 #7
"Hans Kamp" <in**@hanskamp.com> wrote in message
news:bj**********@news3.tilbu1.nb.home.nl...
Visit this page from your server:
http://www.whatismyip.com/
This URL gives the same result on both computers.


Yes, it will if they are both behind the same router. It's giving the ip
address of the router, not actually you're computer. (Type ipconfig ad dos
prompt to see what your computer's actual IP address is)
I found a solution in a different way. I can configure my router by using
"Virtual Servers" (with the Sitecom DC-202 that is
http://192.168.0.1/vs.htm) in which I can type the ports that must be
forwarded and the computer (in the format <ComputerName> (<IP>)
<KindOfConnection> in the combobox). In my case I must give a new name for
my program, giving 4444 as the Internal Port No. and as the External Port
No.

It should be both possible for servers like WinMX, a webserver, a telnet
server, an e-mail and a FTP server, and for the little servers you write
with C#.


Exactly. That's what I meant - sorry if I wasn't clear. Glad you got it
going.

--
Mike Mayer
http://www.mag37.com/csharp/
mi**@mag37.com

Nov 15 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: hyperbob | last post by:
Hello, I'm in the design stage of an application that will consist of two or more processes that will be either on different computers in a network or on the same computer and will have to...
6
by: James Egan | last post by:
I've seen some networking toolkits for C++, but was wondering if there were (or plans for) a standard set of networking classes for C++? Also, can someone tell me where I can find a...
7
by: Brian Keogh | last post by:
Hi, I'm a student learning TCP/IP networking at University. Although I understand all about TCP/IP Networking in Java I am expected to understand the basics of C with regard to these programs as...
46
by: H.A. Sujith | last post by:
Why doesn't the standard library provide (at least basic) networking facilities using TCP/IP ?
4
by: Raj | last post by:
I want to program C with networking. Can anyone tell me the How to start with a small simple program can it possible in turbo/borland c 3+. or i should go for another verson. i am using windows...
0
by: petro | last post by:
I am trying to deploy an asp.net application to my web server. My application uses system.data.oledb to connect to an oracle database. On my development machine I have the oracle client 10g...
2
by: JCB19 | last post by:
I need help networking my HP DV4000 laptop to my home network. I have wireless home network with 3 computers using Linksys Wireless G The laptop has built in wireless capability. I want to...
1
by: ebrimagillen | last post by:
Want to know the difference between URL networking and Socket networking. Also and example from each and the networking technique is most appropriate for the example.
1
by: chinaemerem ibeawuchi | last post by:
What is the difference between URL networking and Socket networking? with an example of each type and state why the choosen networking technique is most appropriate for the example.
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.