Results 1 to 17 of 17

Thread: Winsock IP Question

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2008
    Posts
    1

    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.

  2. #2
    New Member
    Join Date
    Feb 2008
    Posts
    1

    Re: Winsock IP Question

    yea ,, um lookin for the same thing ,, well i really hope if som1 help us about this ,,

  3. #3
    PowerPoster ThEiMp's Avatar
    Join Date
    Dec 2007
    Location
    Take The PCI Bus Across To The CPU!!
    Posts
    3,948

    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...

  4. #4
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    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.
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  5. #5
    New Member
    Join Date
    Dec 2008
    Location
    Billings, MT
    Posts
    2

    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

  6. #6
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    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.
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  7. #7
    PowerPoster ThEiMp's Avatar
    Join Date
    Dec 2007
    Location
    Take The PCI Bus Across To The CPU!!
    Posts
    3,948

    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...

  8. #8
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: Winsock IP Question

    Quote 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.
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  9. #9
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    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)

  10. #10
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    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.
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  11. #11
    New Member
    Join Date
    Mar 2009
    Posts
    1

    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.

  12. #12
    Frenzied Member TheBigB's Avatar
    Join Date
    Mar 2006
    Location
    *Stack Trace*
    Posts
    1,511

    Re: Winsock IP Question

    Find your router here and follow instructions.
    Delete it. They just clutter threads anyway.

  13. #13
    New Member
    Join Date
    Feb 2009
    Posts
    3

    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.
    Gives you some info on visual basic tutorials http://www.vbtraininground.com/

  14. #14
    Frenzied Member TheBigB's Avatar
    Join Date
    Mar 2006
    Location
    *Stack Trace*
    Posts
    1,511

    Re: Winsock IP Question

    That is not VB6.
    Besides it's also winsock, but the .NET version.
    Delete it. They just clutter threads anyway.

  15. #15
    PowerPoster ThEiMp's Avatar
    Join Date
    Dec 2007
    Location
    Take The PCI Bus Across To The CPU!!
    Posts
    3,948

    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...

  16. #16
    Hyperactive Member deathfxu's Avatar
    Join Date
    Mar 2009
    Location
    USA
    Posts
    279

    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:
    1. Private myIPAddress As String
    2.  
    3. Public Function ExternalIP() As String
    4. Static isActive As Boolean
    5. Dim strHTML As String
    6. Dim curUrl As Integer
    7. Dim myUrl(1 To 4) As String
    8. Dim N As Integer
    9.  
    10. Do While isActive
    11.     DoEvents
    12. Loop
    13.  
    14. If myIPAddress <> "" Then
    15.     ExternalIP = myIPAddress
    16.     Exit Function
    17. End If
    18.  
    19. isActive = True
    20.  
    21. myUrl(1) = "http://www.mediacollege.com/internet/utilities/show-ip.shtml"
    22. myUrl(2) = "http://www.lawrencegoetz.com/programs/ipinfo/"
    23. myUrl(3) = "http://ip-adress.com/"
    24. myUrl(4) = "http://showip.net/"
    25.  
    26. For curUrl = 1 To 4
    27.     If frmMain.netMain.StillExecuting Then frmMain.netMain.Cancel 'Cancel inet if it's still doing something.
    28.     strHTML = frmMain.netMain.OpenURL(myUrl(curUrl)) 'Get the HTML source code to the webpage.
    29.     If Len(strHTML) > 0 Then 'Check if the server returned any data.
    30.         myIPAddress = GetIP(strHTML)
    31.         If Len(myIPAddress) > 0 Then
    32.             ExternalIP = myIPAddress
    33.             isActive = False
    34.             Exit Function
    35.         End If
    36.     End If
    37. Next curUrl
    38. myIPAddress = frmMain.sckCon(0).LocalIP
    39. ExternalIP = myIPAddress
    40. isActive = False
    41.  
    42. End Function
    43.  
    44. Private Function GetIP(HTML As String) As String
    45. Dim lastPos As Integer
    46. Dim curPos As Integer
    47. Dim curStr As String
    48. Dim offset As Integer
    49.  
    50. curPos = InStr(2000, HTML, ".")
    51. Do While curPos > 0
    52.  
    53.     curStr = Mid$(HTML, curPos, 1)
    54.  
    55.     offset = -1
    56.     Do While IsIPChar(Mid$(HTML, curPos + offset, 1))
    57.         curStr = Mid$(HTML, curPos + offset, 1) & curStr
    58.         offset = offset - 1
    59.     Loop
    60.  
    61.     offset = 1
    62.     Do While IsIPChar(Mid$(HTML, curPos + offset, 1))
    63.         curStr = curStr & Mid$(HTML, curPos + offset, 1)
    64.         offset = offset + 1
    65.     Loop
    66.  
    67.     If ChkIP(curStr) Then
    68.         GetIP = curStr
    69.         Exit Function
    70.     End If
    71.  
    72.     lastPos = curPos
    73.     curPos = InStr(lastPos + 1, HTML, ".")
    74.  
    75. Loop
    76.  
    77. End Function
    78.  
    79. Private Function ChkIP(IP As String) As Boolean
    80. Dim LastPer As Integer
    81. Dim N As Integer
    82.  
    83. If Len(IP) > 15 Or Len(IP) < 7 Or CountPeriods(IP) <> 3 Then
    84.     ChkIP = False
    85.     Exit Function
    86. End If
    87. For N = 1 To Len(IP)
    88.     If Mid$(IP, N, 1) = "." Then
    89.         LastPer = N
    90.     ElseIf N - LastPer > 3 Or Not IsNum(Mid$(IP, N, 1)) Then
    91.         ChkIP = Fals
    92.         Exit Function
    93.     End If
    94. Next N
    95. ChkIP = True
    96.  
    97. End Function
    98.  
    99. Private Function CountPeriods(chkStr As String) As Integer
    100. Dim Total As Integer
    101. Dim N As Integer
    102.  
    103. For N = 1 To Len(chkStr)
    104.     If Mid$(chkStr, N, 1) = "." Then Total = Total + 1
    105. Next N
    106. CountPeriods = Total
    107.  
    108. End Function
    109.  
    110. Private Function IsIPChar(curChar As String) As Boolean
    111.       IsIPChar = IIf(IsNum(curChar) Or curChar = ".", True, False)
    112. End Function
    113.  
    114. Private Function IsNum(Char As String) As Boolean
    115.  
    116. Select Case Char
    117. Case "0": IsNum = True
    118. Case "1": IsNum = True
    119. Case "2": IsNum = True
    120. Case "3": IsNum = True
    121. Case "4": IsNum = True
    122. Case "5": IsNum = True
    123. Case "6": IsNum = True
    124. Case "7": IsNum = True
    125. Case "8": IsNum = True
    126. Case "9": IsNum = True
    127. Case Else: IsNum = False
    128. End Select
    129.  
    130. End Function
    Last edited by deathfxu; Mar 14th, 2009 at 05:32 PM.

  17. #17
    Frenzied Member Campion's Avatar
    Join Date
    Jul 2007
    Location
    UT
    Posts
    1,098

    Re: Winsock IP Question

    Quote Originally Posted by ThEiMp View Post
    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
  •  



Click Here to Expand Forum to Full Width