|
-
May 5th, 2010, 04:17 AM
#1
Thread Starter
Lively Member
Tcp ip
Hello,
I have a (hopefully) small problem/question.
When I create a TCP server/client it always goes for my network IP.
How do I get this to listen/read the main ip? (the one outside thats: me -> network -> router/modem -> the internet)
Thanks in advance
- Blixa
-
May 5th, 2010, 04:19 AM
#2
Re: Tcp ip
this will cause it to listen to any ip
Code:
listener = New System.Net.Sockets.TcpListener(System.Net.IPAddress.Any, PortNumber)
* Rate It  If you Like it
__________________________________________________________________________________________
" Programming is like sex: one mistake and you’re providing support for a lifetime."
Get last SQL insert ID 
-
May 5th, 2010, 04:43 AM
#3
Thread Starter
Lively Member
Re: Tcp ip
I tried that. How do I figure out on which ip(s) its running?
-
May 5th, 2010, 04:46 AM
#4
Re: Tcp ip
you can get the clinet ip once you accept the tcp request.
Code:
incomingClient = listener.AcceptTcpClient
ClientIP = incomingClient.Client.RemoteEndPoint.ToString()
* Rate It  If you Like it
__________________________________________________________________________________________
" Programming is like sex: one mistake and you’re providing support for a lifetime."
Get last SQL insert ID 
-
May 5th, 2010, 04:49 AM
#5
Thread Starter
Lively Member
Re: Tcp ip
I mean how do I figure out on what IP the server is running at that moment.
-
May 5th, 2010, 04:58 AM
#6
Re: Tcp ip
try
Code:
Dim h As System.Net.IPHostEntry = System.Net.Dns.GetHostEntry(System.Net.Dns.GetHostName)
MessageBox.Show(h.AddressList.GetValue(0).ToString)
* Rate It  If you Like it
__________________________________________________________________________________________
" Programming is like sex: one mistake and you’re providing support for a lifetime."
Get last SQL insert ID 
-
May 5th, 2010, 05:10 AM
#7
Thread Starter
Lively Member
Re: Tcp ip
That seems to work , except it running on IP6 , how can I force IP4?
Edit:
I looped through the whole list but it doesnt give the IP it should, seem only to be local IPs.
I need to connect to an computer at home from work so I need a server to listen the my home's IP.
any suggestion/help/anything?
Last edited by Blixa; May 5th, 2010 at 05:21 AM.
-
May 5th, 2010, 05:28 AM
#8
Re: Tcp ip
First up, your computer can, and does, have multiple IP addresses. Secondly, the IP address of your computer is NOT the IP address that people see on the Internet. Your ISP assigns a public IP address to you and that is what others, e.g. web servers, see when they communicate with you. Your router assigns an internal IP address to your computer, which is how multiple computers can share a single internet connection. Your internal IP address is useless if you want to be able to communicate with someone across the internet.
If you want to communicate with the outside world then you need to know the IP address that your ISP assigned to you. If you have a static IP address then your ISP will have already told you what it is. Whether it's static or dynamic, you should be able to get it from the property pages of your router. If you want to communicate with the outside world then you'll also have to set up port forwarding on your router, which is well beyond the scope of a VB forum. If you have a dynamic IP address then you'll have to let anyone who you want to be able to contact you know what it is first, which is why you should get a static IP address if you want to run servers.
-
May 5th, 2010, 05:30 AM
#9
Thread Starter
Lively Member
Re: Tcp ip
I know my own IP address.
and I basicly need to forward port 99999 to my pc?
thanks for the replys so far
-
May 5th, 2010, 05:34 AM
#10
Re: Tcp ip
Code:
'yahoo as ip
Dim ip As System.Net.IPAddress = System.Net.IPAddress.Parse("209.191.122.70")
'reverse lookup
Dim he As System.Net.IPHostEntry = System.Net.Dns.GetHostEntry(ip)
'check addresses
For Each foo In he.AddressList
If foo.AddressFamily = Net.Sockets.AddressFamily.InterNetwork Then
'ipv4
Stop
ElseIf foo.AddressFamily = Net.Sockets.AddressFamily.InterNetworkV6 Then
'ipv6
Stop
End If
Next
-
May 5th, 2010, 05:38 AM
#11
Re: Tcp ip
Did your ISP provide you a public IP address, or arrange to have port 99,999 forwarded to your network. I doubt the latter as that is not a legal port number.
-
May 5th, 2010, 05:46 AM
#12
Thread Starter
Lively Member
Re: Tcp ip
I have a public IP, the 99999 was just an example.
-
May 5th, 2010, 05:50 AM
#13
Re: Tcp ip
So then, if someone wants to contact you across the internet then they need to specify your public IP address and a port number. You will have to have forwarded that port number to your computer on your router. Obviously you must set up port forwarding first, then tell the clients what port number to use. The code is exactly the same whether you're communicating across your LAN or over the internet: you specify an IP address and a port number. The difference is who receives and interprets those values: the server itself or the router.
-
May 5th, 2010, 05:54 AM
#14
Re: Tcp ip
 Originally Posted by jmcilhinney
So then, if someone wants to contact you across the internet then they need to specify your public IP address and a port number. You will have to have forwarded that port number to your computer on your router. Obviously you must set up port forwarding first, then tell the clients what port number to use. The code is exactly the same whether you're communicating across your LAN or over the internet: you specify an IP address and a port number. The difference is who receives and interprets those values: the server itself or the router.
Agreed. If you have this set up properly, the only thing that can go wrong is if the ISP is blocking the port you are trying to use.
-
May 5th, 2010, 06:12 AM
#15
Thread Starter
Lively Member
Re: Tcp ip
ok thanks for the help ganna try to get this working.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|