How to id IP address - LAN and Internet - using TClientSocket and TSer - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

How to id IP address - LAN and Internet - using TClientSocket and TSer

Hi, I used to have IP addresses explicitly defined on my LAN, and my apps communicated ok using TClientSocket and TServerSocket (IP address was hard-coded).

Now that I have changed this to obtain an IP address automatically, I need to find out my IP address at run time for my apps to communicate, over the LAN and over the internet.

a) How can I discover my IP address, please ?
b) Does it matter that I am using a broadband connection ? I wish to use my app on dial up connections too

I'm using Delphi 6.

Many, Many thanx - Gazza (newbie)

Comments

  • ManningManning Posts: 1,621Member
    : Hi, I used to have IP addresses explicitly defined on my LAN, and my apps communicated ok using TClientSocket and TServerSocket (IP address was hard-coded).
    :
    : Now that I have changed this to obtain an IP address automatically, I need to find out my IP address at run time for my apps to communicate, over the LAN and over the internet.
    :
    : a) How can I discover my IP address, please ?
    : b) Does it matter that I am using a broadband connection ? I wish to use my app on dial up connections too
    :
    : I'm using Delphi 6.

    What exactly is it you are trying to do? Do you want the client to find the IP address of the server? That's not really practical. You have to tell a client where to connect to, it can't just pull IP addresses out of a hat.

    Is that what you're asking? If not, please explain with better detail.
  • GarryPaxtonGarryPaxton Posts: 66Member
    : : Hi, I used to have IP addresses explicitly defined on my LAN, and my apps communicated ok using TClientSocket and TServerSocket (IP address was hard-coded).
    : :
    : : Now that I have changed this to obtain an IP address automatically, I need to find out my IP address at run time for my apps to communicate, over the LAN and over the internet.
    : :
    : : a) How can I discover my IP address, please ?
    : : b) Does it matter that I am using a broadband connection ? I wish to use my app on dial up connections too
    : :
    : : I'm using Delphi 6.
    :
    : What exactly is it you are trying to do? Do you want the client to find the IP address of the server? That's not really practical. You have to tell a client where to connect to, it can't just pull IP addresses out of a hat.
    :
    : Is that what you're asking? If not, please explain with better detail.
    :
    Well, basically I'd like two PCs to communicate. The apps are simply passing strings back and forth.

    That's fairly easy across my home LAN where I can set IP addresses explicitly. In the client app, I can hardcode the IP address of the server, and while the server is in 'listening' mode, set the ClientSocket.Host of any client app to the pre-set IPaddr of the Server. Hey presto, connected.

    But to talk across the internet seems a more complex task. This is because the IPaddr of the server is no longer constant, as it's determined by my ISP. Consequently, my client apps cannot have the server IP address 'hard-coded' when use on the net.

    I don't really understand how to approach the problem, but have guessed that I can probably set up another app somewhere else, for example, on my website, which collects the current IP address of any of my apps dotted around the internet - that's the first place they check in to confirm their online presence. Client apps will consult this table of IP addresses to find out where the server(s) are. So my starting point was...How do I find out the IP address that has been allocated to me by my ISP today ? And start from there. Its difficult to define the problem more explicity as it is more an issue of 'how do I approach this' ? Maybe my appraoch is totally wrong. thanx for advice on way forward. Gazza
  • PerranPerran Posts: 241Member
    : : : Hi, I used to have IP addresses explicitly defined on my LAN, and my apps communicated ok using TClientSocket and TServerSocket (IP address was hard-coded).
    : : :
    : : : Now that I have changed this to obtain an IP address automatically, I need to find out my IP address at run time for my apps to communicate, over the LAN and over the internet.
    : : :
    : : : a) How can I discover my IP address, please ?
    : : : b) Does it matter that I am using a broadband connection ? I wish to use my app on dial up connections too
    : : :
    : : : I'm using Delphi 6.
    : :
    : : What exactly is it you are trying to do? Do you want the client to find the IP address of the server? That's not really practical. You have to tell a client where to connect to, it can't just pull IP addresses out of a hat.
    : :
    : : Is that what you're asking? If not, please explain with better detail.
    : :
    : Well, basically I'd like two PCs to communicate. The apps are simply passing strings back and forth.
    :
    : That's fairly easy across my home LAN where I can set IP addresses explicitly. In the client app, I can hardcode the IP address of the server, and while the server is in 'listening' mode, set the ClientSocket.Host of any client app to the pre-set IPaddr of the Server. Hey presto, connected.
    :
    : But to talk across the internet seems a more complex task. This is because the IPaddr of the server is no longer constant, as it's determined by my ISP. Consequently, my client apps cannot have the server IP address 'hard-coded' when use on the net.
    :
    : I don't really understand how to approach the problem, but have guessed that I can probably set up another app somewhere else, for example, on my website, which collects the current IP address of any of my apps dotted around the internet - that's the first place they check in to confirm their online presence. Client apps will consult this table of IP addresses to find out where the server(s) are. So my starting point was...How do I find out the IP address that has been allocated to me by my ISP today ? And start from there. Its difficult to define the problem more explicity as it is more an issue of 'how do I approach this' ? Maybe my appraoch is totally wrong. thanx for advice on way forward. Gazza
    :
    Are you sure that the IP address of the server is not constant? It should be. If your going to use the same server all the time, determine the server address by pinging it and hard-code it in. At least you could do that for testing. I use D6 and have those Indy components. There's a DNS name resolver component that you could use. It might be worth poking around in the Internet Standards documents.
  • ManningManning Posts: 1,621Member
    : : : Hi, I used to have IP addresses explicitly defined on my LAN, and my apps communicated ok using TClientSocket and TServerSocket (IP address was hard-coded).
    : : :
    : : : Now that I have changed this to obtain an IP address automatically, I need to find out my IP address at run time for my apps to communicate, over the LAN and over the internet.
    : : :
    : : : a) How can I discover my IP address, please ?
    : : : b) Does it matter that I am using a broadband connection ? I wish to use my app on dial up connections too
    : : :
    : : : I'm using Delphi 6.
    : :
    : : What exactly is it you are trying to do? Do you want the client to find the IP address of the server? That's not really practical. You have to tell a client where to connect to, it can't just pull IP addresses out of a hat.
    : :
    : : Is that what you're asking? If not, please explain with better detail.
    : :
    : Well, basically I'd like two PCs to communicate. The apps are simply passing strings back and forth.
    :
    : That's fairly easy across my home LAN where I can set IP addresses explicitly. In the client app, I can hardcode the IP address of the server, and while the server is in 'listening' mode, set the ClientSocket.Host of any client app to the pre-set IPaddr of the Server. Hey presto, connected.
    :
    : But to talk across the internet seems a more complex task. This is because the IPaddr of the server is no longer constant, as it's determined by my ISP. Consequently, my client apps cannot have the server IP address 'hard-coded' when use on the net.
    :
    : I don't really understand how to approach the problem, but have guessed that I can probably set up another app somewhere else, for example, on my website, which collects the current IP address of any of my apps dotted around the internet - that's the first place they check in to confirm their online presence. Client apps will consult this table of IP addresses to find out where the server(s) are. So my starting point was...How do I find out the IP address that has been allocated to me by my ISP today ? And start from there. Its difficult to define the problem more explicity as it is more an issue of 'how do I approach this' ? Maybe my appraoch is totally wrong. thanx for advice on way forward. Gazza
    :


    Okay, so you do want to do what I thought. It sounds like you need to sign up with a Dynamic DNS service. A good one I used to use is available at http://www.myip.us.
  • GarryPaxtonGarryPaxton Posts: 66Member
    : : : : Hi, I used to have IP addresses explicitly defined on my LAN, and my apps communicated ok using TClientSocket and TServerSocket (IP address was hard-coded).
    : : : :
    : : : : Now that I have changed this to obtain an IP address automatically, I need to find out my IP address at run time for my apps to communicate, over the LAN and over the internet.
    : : : :
    : : : : a) How can I discover my IP address, please ?
    : : : : b) Does it matter that I am using a broadband connection ? I wish to use my app on dial up connections too
    : : : :
    : : : : I'm using Delphi 6.
    : : :
    : : : What exactly is it you are trying to do? Do you want the client to find the IP address of the server? That's not really practical. You have to tell a client where to connect to, it can't just pull IP addresses out of a hat.
    : : :
    : : : Is that what you're asking? If not, please explain with better detail.
    : : :
    : : Well, basically I'd like two PCs to communicate. The apps are simply passing strings back and forth.
    : :
    : : That's fairly easy across my home LAN where I can set IP addresses explicitly. In the client app, I can hardcode the IP address of the server, and while the server is in 'listening' mode, set the ClientSocket.Host of any client app to the pre-set IPaddr of the Server. Hey presto, connected.
    : :
    : : But to talk across the internet seems a more complex task. This is because the IPaddr of the server is no longer constant, as it's determined by my ISP. Consequently, my client apps cannot have the server IP address 'hard-coded' when use on the net.
    : :
    : : I don't really understand how to approach the problem, but have guessed that I can probably set up another app somewhere else, for example, on my website, which collects the current IP address of any of my apps dotted around the internet - that's the first place they check in to confirm their online presence. Client apps will consult this table of IP addresses to find out where the server(s) are. So my starting point was...How do I find out the IP address that has been allocated to me by my ISP today ? And start from there. Its difficult to define the problem more explicity as it is more an issue of 'how do I approach this' ? Maybe my appraoch is totally wrong. thanx for advice on way forward. Gazza
    : :
    :
    :
    : Okay, so you do want to do what I thought. It sounds like you need to sign up with a Dynamic DNS service. A good one I used to use is available at http://www.myip.us.
    :

    Ok thanks. As a final consideration, my app is likely to be distributed to individuals with a very small circle of contacts. A typical example is a disabled lady living in a residential home, who will use the app to 'chat' to a daughter in her house, living abroad, both of whom are using a local dial-up to the internet. The app sits on each PC and 'listens'. It can become a client or server app...if contacted, it becomes the server, and the contacting app becomes the client.

    There are a large number of clients interested in this idea, so I can envisage quite a few of these one-to-one connections taking place at any time. Each pair will of course include one as server, one as client. And of course, each pair has nothing to do with any other 'pairs' currently in dialogue.

    To clarify, does this mean I would need to get at least one of each pair to sign up with the site you recommend?
  • ManningManning Posts: 1,621Member
    : : : : : Hi, I used to have IP addresses explicitly defined on my LAN, and my apps communicated ok using TClientSocket and TServerSocket (IP address was hard-coded).
    : : : : :
    : : : : : Now that I have changed this to obtain an IP address automatically, I need to find out my IP address at run time for my apps to communicate, over the LAN and over the internet.
    : : : : :
    : : : : : a) How can I discover my IP address, please ?
    : : : : : b) Does it matter that I am using a broadband connection ? I wish to use my app on dial up connections too
    : : : : :
    : : : : : I'm using Delphi 6.
    : : : :
    : : : : What exactly is it you are trying to do? Do you want the client to find the IP address of the server? That's not really practical. You have to tell a client where to connect to, it can't just pull IP addresses out of a hat.
    : : : :
    : : : : Is that what you're asking? If not, please explain with better detail.
    : : : :
    : : : Well, basically I'd like two PCs to communicate. The apps are simply passing strings back and forth.
    : : :
    : : : That's fairly easy across my home LAN where I can set IP addresses explicitly. In the client app, I can hardcode the IP address of the server, and while the server is in 'listening' mode, set the ClientSocket.Host of any client app to the pre-set IPaddr of the Server. Hey presto, connected.
    : : :
    : : : But to talk across the internet seems a more complex task. This is because the IPaddr of the server is no longer constant, as it's determined by my ISP. Consequently, my client apps cannot have the server IP address 'hard-coded' when use on the net.
    : : :
    : : : I don't really understand how to approach the problem, but have guessed that I can probably set up another app somewhere else, for example, on my website, which collects the current IP address of any of my apps dotted around the internet - that's the first place they check in to confirm their online presence. Client apps will consult this table of IP addresses to find out where the server(s) are. So my starting point was...How do I find out the IP address that has been allocated to me by my ISP today ? And start from there. Its difficult to define the problem more explicity as it is more an issue of 'how do I approach this' ? Maybe my appraoch is totally wrong. thanx for advice on way forward. Gazza
    : : :
    : :
    : :
    : : Okay, so you do want to do what I thought. It sounds like you need to sign up with a Dynamic DNS service. A good one I used to use is available at http://www.myip.us.
    : :
    :
    : Ok thanks. As a final consideration, my app is likely to be distributed to individuals with a very small circle of contacts. A typical example is a disabled lady living in a residential home, who will use the app to 'chat' to a daughter in her house, living abroad, both of whom are using a local dial-up to the internet. The app sits on each PC and 'listens'. It can become a client or server app...if contacted, it becomes the server, and the contacting app becomes the client.
    :
    : There are a large number of clients interested in this idea, so I can envisage quite a few of these one-to-one connections taking place at any time. Each pair will of course include one as server, one as client. And of course, each pair has nothing to do with any other 'pairs' currently in dialogue.
    :
    : To clarify, does this mean I would need to get at least one of each pair to sign up with the site you recommend?


    Yes, anyone who wants to potentially act as the server would have to have an account with their own unique hostname. But with the extra details you provided, it sounds like your original idea of having another server that tracks the user names and ip addresses of any servers that the clients could then query to see if their server is online may work better.

    Unfortunately I had a HD crash yesterday and I lost all my source code, otherwise I would have been able to provide you with the code to find out your local IP address. Since I can't now, I can only recommend going to www.torry.net and browsing the components their, or searching on Google for some code snippets.

    I think also if you search on the C programming board I remember some code being posted not long ago. Since it's mainly WinAPI calls, it'll transfer to Delphi quite easily.
  • GarryPaxtonGarryPaxton Posts: 66Member
    : : : : : : Hi, I used to have IP addresses explicitly defined on my LAN, and my apps communicated ok using TClientSocket and TServerSocket (IP address was hard-coded).
    : : : : : :
    : : : : : : Now that I have changed this to obtain an IP address automatically, I need to find out my IP address at run time for my apps to communicate, over the LAN and over the internet.
    : : : : : :
    : : : : : : a) How can I discover my IP address, please ?
    : : : : : : b) Does it matter that I am using a broadband connection ? I wish to use my app on dial up connections too
    : : : : : :
    : : : : : : I'm using Delphi 6.
    : : : : :
    : : : : : What exactly is it you are trying to do? Do you want the client to find the IP address of the server? That's not really practical. You have to tell a client where to connect to, it can't just pull IP addresses out of a hat.
    : : : : :
    : : : : : Is that what you're asking? If not, please explain with better detail.
    : : : : :
    : : : : Well, basically I'd like two PCs to communicate. The apps are simply passing strings back and forth.
    : : : :
    : : : : That's fairly easy across my home LAN where I can set IP addresses explicitly. In the client app, I can hardcode the IP address of the server, and while the server is in 'listening' mode, set the ClientSocket.Host of any client app to the pre-set IPaddr of the Server. Hey presto, connected.
    : : : :
    : : : : But to talk across the internet seems a more complex task. This is because the IPaddr of the server is no longer constant, as it's determined by my ISP. Consequently, my client apps cannot have the server IP address 'hard-coded' when use on the net.
    : : : :
    : : : : I don't really understand how to approach the problem, but have guessed that I can probably set up another app somewhere else, for example, on my website, which collects the current IP address of any of my apps dotted around the internet - that's the first place they check in to confirm their online presence. Client apps will consult this table of IP addresses to find out where the server(s) are. So my starting point was...How do I find out the IP address that has been allocated to me by my ISP today ? And start from there. Its difficult to define the problem more explicity as it is more an issue of 'how do I approach this' ? Maybe my appraoch is totally wrong. thanx for advice on way forward. Gazza
    : : : :
    : : :
    : : :
    : : : Okay, so you do want to do what I thought. It sounds like you need to sign up with a Dynamic DNS service. A good one I used to use is available at http://www.myip.us.
    : : :
    : :
    : : Ok thanks. As a final consideration, my app is likely to be distributed to individuals with a very small circle of contacts. A typical example is a disabled lady living in a residential home, who will use the app to 'chat' to a daughter in her house, living abroad, both of whom are using a local dial-up to the internet. The app sits on each PC and 'listens'. It can become a client or server app...if contacted, it becomes the server, and the contacting app becomes the client.
    : :
    : : There are a large number of clients interested in this idea, so I can envisage quite a few of these one-to-one connections taking place at any time. Each pair will of course include one as server, one as client. And of course, each pair has nothing to do with any other 'pairs' currently in dialogue.
    : :
    : : To clarify, does this mean I would need to get at least one of each pair to sign up with the site you recommend?
    :
    :
    : Yes, anyone who wants to potentially act as the server would have to have an account with their own unique hostname. But with the extra details you provided, it sounds like your original idea of having another server that tracks the user names and ip addresses of any servers that the clients could then query to see if their server is online may work better.
    :
    : Unfortunately I had a HD crash yesterday and I lost all my source code, otherwise I would have been able to provide you with the code to find out your local IP address. Since I can't now, I can only recommend going to www.torry.net and browsing the components their, or searching on Google for some code snippets.
    :
    : I think also if you search on the C programming board I remember some code being posted not long ago. Since it's mainly WinAPI calls, it'll transfer to Delphi quite easily.
    :
    OK - I have enough to go off and do some research. many thanks for advice , Gazza
Sign In or Register to comment.