|
-
Dec 6th, 2008, 08:12 PM
#1
Thread Starter
New Member
Winsock IP Question
First of all im using a router.
I Made A Simple Two Way(Server & Client) Chat Program Using Winsock..
I use my desktop comp as the server, and my laptop as the client.
but the thing is my desktop computer always host with the ip of 192.168.0.xxx not the real ip(ie:68.39.138.144) given from my isp.
if i take my laptop some where else and use a different internet service provider... how can I connect to my desktop computer's server chat program i made.
-
Dec 12th, 2008, 12:43 PM
#2
New Member
Re: Winsock IP Question
yea ,, um lookin for the same thing ,, well i really hope if som1 help us about this ,,
-
Dec 13th, 2008, 08:11 PM
#3
PowerPoster
Re: Winsock IP Question
Easy using a remote Winsock host connection.
I have a huge free products range, of computer software in which you can download using any kind of 64-Bit Web Browser. Also there is coming a Social Networking section that I am making on my Website...
|Ambra Productions Inc. | The Black Sun Society | The Black Shield | Ambra College | Church of the Black Sun | Ambra Productions Inc's Homepage | Boomtick Venues: Ambar Nightclub, Jack Rabbit Slim's, Villa Nightclub and Lucy's Love Shack | Pasta Ambra | Fish Feast Company | Wallet Wizard | Ambrose Liquor | Ambar Tavern | Ambra University | Ambra Cheese |
Do you wish to do unpaid work for me??? If so, the PM me on this Forum, and then we can get to work, programming for the future of computers go by the name of ThEiMp. This is my ghost writers name. Also my nickname, means that I am: The Imperial of the Technology Industry, so then to make it really short, I just then wrote: The Imp, which is where I get the nickname from...
-
Dec 15th, 2008, 08:33 AM
#4
Re: Winsock IP Question
Basically you need to forward the port that your program is using to communicate through your router. I'll explain...
The IP your ISP gives you (68.39.138.144 or whatever) is no more of a 'real' IP than the IP of 192.168.0.X. Its just that your ISP assigns you a public IP, where as your router assigns you an internal (aka LAN) IP. The main difference, apart from subnet masks etc etc that I wont get into, is that the IP your ISP gives you must be unique. E.g no one else in the world should have that same public IP. Where as your LAN IPs can be the same as anyone elses, as long as they are not the same as another PC on the same network as you.
Essentially your home network is invisible to the rest of the world, but your public IP (from your ISP) is not. So, what we need to do is tell your router to pass certain data that is sent to your visible Public IP through to a specific computer on your LAN (home network).
For example, lets say your app uses port 1590 (just a random one) to send and recieve information to and from the client/server. When you use this on your home network (which is on the 'internal' side of your router) then there's no problem because all ports are allowed to pass between computers on your network, assuming you dont have any other firewall software running on each PC anyway.
However, when you send data to your external IP on that port, it hits your router and if your router has no port forwarding rule that matches that port (1590) then it just discards the packets.
The way to resolve this, is to setup a Port Forwarding rule on your router so that all packets recieved by your router on its external (public) side will get passed through to the PC on your home network that is running your server application.
The way to do this varies from router to router but it usually follows the same general methods:
1. Create a 'Service' on your router and tell it to use port 1590 (example) and name it whatever you like.
2. Create a port forwarding rule that uses that service you just created and tell it to forward packets to the internal IP address of your PC that is running your server app (the 192.168.0.X address). If you dont know what IP your server PC has, just type IPCONFIG from a command prompt window and it will tell you.
Oh and if you dont know how to get onto your router to do any of this, most modern routers have a web interface that you can use. So just open internet explorer and go to http://192.168.0.254 (change that IP to whatever IP your router has)
Now you may have noticed that you dont always get the same internal IP address each time you turn your PC on. So if you setup your port forwarding rule to go to 192.168.0.10 and then in a few days time your PC picks up an IP of 192.168.0.11 then your port forwarding rule no longer works the way you want it to because its trying to forward packets to an IP that doesnt exist (or has been assigned to a different device).
The way to get around this is to either setup a static IP on your PC (google it) or (and this is the method I would recommend) setup a reservation for your PCs MAC address in your router so that it always reserves the same IP for your PC. I know you might not understand any of that, but do a bit of research and you will see its pretty simple and easy to do.
So yeah, once you have setup the port forwarding rule, you just tell your client app to establish its winsock connection to your external IP (the one your ISP gives you) using the port that you setup the rule to use, instead of going to your internal IP like you normally would.
Hope that helps.
Last edited by chris128; Dec 15th, 2008 at 09:09 AM.
-
Dec 18th, 2008, 03:40 PM
#5
New Member
Re: Winsock IP Question
chris128 -
I understand your directions, but does your ISP always provide you the SAME IP address? I could be wrong, but I thought that was dynamic as well...
Let us know.
Thanks
-
Dec 18th, 2008, 04:56 PM
#6
Re: Winsock IP Question
It depends which part of the world you live in and what ISP you have. Most ISPs in the Uk will tell you its dynamic but then it very very rarely changes. I've had the same IP for about 6 months now. Of course pretty much any business will have its own Static Public IP which is always the same, so if you are trying to do this in a business environment then you shouldnt have any problems.
-
Dec 18th, 2008, 07:27 PM
#7
PowerPoster
Re: Winsock IP Question
Its not the ISP that despenses a IP address, it is the network hardware. ENTERnet card, modem etc. I guess. But the ISP does know your ip address though, after it has been found on their system.
You can have a dynamic ip address. If so, then use this address, which is default and will work for any address assignment that is found on the system. '127.0.0.1'.
I have a huge free products range, of computer software in which you can download using any kind of 64-Bit Web Browser. Also there is coming a Social Networking section that I am making on my Website...
|Ambra Productions Inc. | The Black Sun Society | The Black Shield | Ambra College | Church of the Black Sun | Ambra Productions Inc's Homepage | Boomtick Venues: Ambar Nightclub, Jack Rabbit Slim's, Villa Nightclub and Lucy's Love Shack | Pasta Ambra | Fish Feast Company | Wallet Wizard | Ambrose Liquor | Ambar Tavern | Ambra University | Ambra Cheese |
Do you wish to do unpaid work for me??? If so, the PM me on this Forum, and then we can get to work, programming for the future of computers go by the name of ThEiMp. This is my ghost writers name. Also my nickname, means that I am: The Imperial of the Technology Industry, so then to make it really short, I just then wrote: The Imp, which is where I get the nickname from...
-
Dec 18th, 2008, 07:56 PM
#8
Re: Winsock IP Question
 Originally Posted by ThEiMp
Its not the ISP that despenses a IP address, it is the network hardware. ENTERnet card, modem etc. I guess. But the ISP does know your ip address though, after it has been found on their system.
You can have a dynamic ip address. If so, then use this address, which is default and will work for any address assignment that is found on the system. '127.0.0.1'.
You are wrong...Read my post above.
Your ISP gives you your PUBLIC IP address, your router gives you an internal PRIVATE IP address. I did explain all this in detail in my lengthy post above so I'm not going to go through it all again.
Also as for the IP address 127.0.0.1, that is what is known as the 'loopback' address and basically means "myself". So if you try to connect to 127.0.0.1 from any computer in the world, you are just trying to connect it to itself.
So your suggestion of using that address is useless I'm afraid as no other computer can connect to you on that address... because as I just explained, it always relates to whichever computer your using.
-
Dec 20th, 2008, 05:02 AM
#9
Re: Winsock IP Question
As Chris has pointed out, whether your ISP allocated IP Address is static or not is up to the service provider. In my experience, over here, you can ask for a static IP address but it costs money! (also, in my experience, I am allocated a different IP address every time the router connects to the Internet)
A solution I use is to use a free dynamic DNS provider (in my case, no-ip.com but there are plenty of others about). Using their service you can 'register' your IP Address in the global domain and give it a name (eg doogle.no-ip.com). In the Client application, instead of attempting to connect a given IP Address you'd use the name instead.
eq
Code:
Winsock1.RemoteHost = "doogle.no-ip.com"
When that is executed ,the network will use the global DNS to resolve the name into an address and communications will be established. (Given you've gone through the Port Forwarding described by Chris)
Most of these dynamic DNS service providers also supply some code which is installed on your pc which detects if the external IP address has changed and if so will automatically update the global DNS with the new address. Thus, you end up using a name which never changes rather than a dynamic address which does (could)
-
Dec 20th, 2008, 09:41 AM
#10
Re: Winsock IP Question
Ah yes, good suggestion doogle, I forgot all about those dynamic DNS apps/services I guess I must just be lucky that I've always got the same IP then as like I said its been the same for about 6 months and I'm just on a normal home broadband service.
-
Mar 6th, 2009, 04:31 AM
#11
New Member
Re: Winsock IP Question
I'm sorry if my post is considered as necro, but I have the exact same problem here.
Okay, I've made a very simple winsock chatting application. I've succesfully tested it with the loopback address and LAN address (192.168.x.x).
But when I tested it with my friend over the net, it fails.
My program flow :
1) choose to be a server or client
2) If server, input port number and IP, bind, and then listen.
3) if client, input port number and IP to connect, then connect.
4) send and receiving data
at the first test over the net, I used my loopback address to bind the socket. Ask my friend to connect. well it failed. Yes, i know why it fails.
the second test, I'm using my LAN (192.168.x.x) and failed 
Figuring out that 192.168.x.x is used for local network, I planned to test it with my external IP. So, I start my program, be the server, enter whatever port that I'm sure it's free and enter my external IP (or public??) that I got from whatismyip.com - now the server can't bind the socket 
I've tried to google about "how to connect other people over the net with winsock". But what I find can't solve my problem.
....
The way to resolve this, is to setup a Port Forwarding rule on your router so that all packets recieved by your router on its external (public) side will get passed through to the PC on your home network that is running your server application.
The way to do this varies from router to router but it usually follows the same general methods:
1. Create a 'Service' on your router and tell it to use port 1590 (example) and name it whatever you like.
2. Create a port forwarding rule that uses that service you just created and tell it to forward packets to the internal IP address of your PC that is running your server app (the 192.168.0.X address). If you dont know what IP your server PC has, just type IPCONFIG from a command prompt window and it will tell you.
Oh and if you dont know how to get onto your router to do any of this, most modern routers have a web interface that you can use. So just open internet explorer and go to http://192.168.0.254 (change that IP to whatever IP your router has)
....
I've tried this too. But I got lost.
When I open http://192.168.x.x that I got from IPCONFIG (I use the Default Gateway IP), it connects me to mikrotik website. I did search inside the web for "Port forwarding" but it returned 0 result.
Anybody can help?
I'm totally get lost here.
What I need is make my program able to chat with someone over the net.
-
Mar 6th, 2009, 09:01 AM
#12
Re: Winsock IP Question
Find your router here and follow instructions.
Delete it. They just clutter threads anyway.
-
Mar 10th, 2009, 05:27 PM
#13
New Member
Re: Winsock IP Question
http://www.vbtraininground.com/?p=56 If you're interested this shows you how to make a simple program like that but with imports instead of winsock.
-
Mar 12th, 2009, 03:38 AM
#14
Re: Winsock IP Question
That is not VB6.
Besides it's also winsock, but the .NET version.
Delete it. They just clutter threads anyway.
-
Mar 13th, 2009, 02:25 AM
#15
PowerPoster
Re: Winsock IP Question
But in VB .NET you don't use Winsock, but you use the Internal Networking IP controls.
I have a huge free products range, of computer software in which you can download using any kind of 64-Bit Web Browser. Also there is coming a Social Networking section that I am making on my Website...
|Ambra Productions Inc. | The Black Sun Society | The Black Shield | Ambra College | Church of the Black Sun | Ambra Productions Inc's Homepage | Boomtick Venues: Ambar Nightclub, Jack Rabbit Slim's, Villa Nightclub and Lucy's Love Shack | Pasta Ambra | Fish Feast Company | Wallet Wizard | Ambrose Liquor | Ambar Tavern | Ambra University | Ambra Cheese |
Do you wish to do unpaid work for me??? If so, the PM me on this Forum, and then we can get to work, programming for the future of computers go by the name of ThEiMp. This is my ghost writers name. Also my nickname, means that I am: The Imperial of the Technology Industry, so then to make it really short, I just then wrote: The Imp, which is where I get the nickname from...
-
Mar 14th, 2009, 05:26 PM
#16
Hyperactive Member
Re: Winsock IP Question
There are several situations that would cause the person to have to go back to no-ip.com or create a new port forwarding rule.
Here is some code anyone can use on any machine, where ever they are, no matter what computer is server, that returns the external IP simply by "myVar = ExternalIP()", so when winsock tries to connect over the internet, it'll work. Put an Internet Transfer Control (msinet.ocx) "netMain" on your form, and don't forget to rename "sckCon(0)" (winsock) and "frmMain" (form).
vb Code:
Private myIPAddress As String Public Function ExternalIP() As String Static isActive As Boolean Dim strHTML As String Dim curUrl As Integer Dim myUrl(1 To 4) As String Dim N As Integer Do While isActive DoEvents Loop If myIPAddress <> "" Then ExternalIP = myIPAddress Exit Function End If isActive = True myUrl(1) = "http://www.mediacollege.com/internet/utilities/show-ip.shtml" myUrl(2) = "http://www.lawrencegoetz.com/programs/ipinfo/" myUrl(3) = "http://ip-adress.com/" myUrl(4) = "http://showip.net/" For curUrl = 1 To 4 If frmMain.netMain.StillExecuting Then frmMain.netMain.Cancel 'Cancel inet if it's still doing something. strHTML = frmMain.netMain.OpenURL(myUrl(curUrl)) 'Get the HTML source code to the webpage. If Len(strHTML) > 0 Then 'Check if the server returned any data. myIPAddress = GetIP(strHTML) If Len(myIPAddress) > 0 Then ExternalIP = myIPAddress isActive = False Exit Function End If End If Next curUrl myIPAddress = frmMain.sckCon(0).LocalIP ExternalIP = myIPAddress isActive = False End Function Private Function GetIP(HTML As String) As String Dim lastPos As Integer Dim curPos As Integer Dim curStr As String Dim offset As Integer curPos = InStr(2000, HTML, ".") Do While curPos > 0 curStr = Mid$(HTML, curPos, 1) offset = -1 Do While IsIPChar(Mid$(HTML, curPos + offset, 1)) curStr = Mid$(HTML, curPos + offset, 1) & curStr offset = offset - 1 Loop offset = 1 Do While IsIPChar(Mid$(HTML, curPos + offset, 1)) curStr = curStr & Mid$(HTML, curPos + offset, 1) offset = offset + 1 Loop If ChkIP(curStr) Then GetIP = curStr Exit Function End If lastPos = curPos curPos = InStr(lastPos + 1, HTML, ".") Loop End Function Private Function ChkIP(IP As String) As Boolean Dim LastPer As Integer Dim N As Integer If Len(IP) > 15 Or Len(IP) < 7 Or CountPeriods(IP) <> 3 Then ChkIP = False Exit Function End If For N = 1 To Len(IP) If Mid$(IP, N, 1) = "." Then LastPer = N ElseIf N - LastPer > 3 Or Not IsNum(Mid$(IP, N, 1)) Then ChkIP = Fals Exit Function End If Next N ChkIP = True End Function Private Function CountPeriods(chkStr As String) As Integer Dim Total As Integer Dim N As Integer For N = 1 To Len(chkStr) If Mid$(chkStr, N, 1) = "." Then Total = Total + 1 Next N CountPeriods = Total End Function Private Function IsIPChar(curChar As String) As Boolean IsIPChar = IIf(IsNum(curChar) Or curChar = ".", True, False) End Function Private Function IsNum(Char As String) As Boolean Select Case Char Case "0": IsNum = True Case "1": IsNum = True Case "2": IsNum = True Case "3": IsNum = True Case "4": IsNum = True Case "5": IsNum = True Case "6": IsNum = True Case "7": IsNum = True Case "8": IsNum = True Case "9": IsNum = True Case Else: IsNum = False End Select End Function
Last edited by deathfxu; Mar 14th, 2009 at 05:32 PM.
-
Mar 18th, 2009, 04:31 PM
#17
Re: Winsock IP Question
 Originally Posted by ThEiMp
But in VB .NET you don't use Winsock, but you use the Internal Networking IP controls.
The Sockets namespace is what you were looking for.
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
|