• ### Popular Now

• 12
• 10
• 10
• 13
• 10

#### Archived

This topic is now archived and is closed to further replies.

# Delphi 5 pro and internet

This topic is 6481 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hello, Well I have Delphi 5 pro which means that I have a LOT of internet components, but that also means that I have never needed to know how winsock works. Apart from that until now I have never needed true network support. I still don’t need to know exactly how winsock works, I just need some basic stuff which can’t be achieved with the components I have. Now on to the questions: 1. How can check if there is an already established connection to the internet? These dial-up connection dialogs really annoy me, so I’d like to establish connections only if my computer is already connected to the internet. 2. How can I get the computer’s IP address and name at runtime? 3. A server should listen on a specific port, that all clients know, but how does one move this connection to another port, so the listening port remains free? Or is this handled automatically Do the fastnet components handle this automatically? 4. And lastly, how can I find another computer on the internet? I know, that for a server computer one can specify either the IP or the name (for example ‘www.netmastersllc.com’), but how can one find a computer, that is not a server? I’m sort of a beginner in network programming, so I’m sorry if these are typical “new baby” questions. Thanks for your help, Pascalix Ps: I see turbo still has the strange yellow color *sigh*

##### Share on other sites
Hi Pascalix,
WinSock Tutorial on gamedev.net will answer most of your questions (apart from Number 1).
The tutorial is written for C but it''s easy to port, you can find it here :
http://www.gamedev.net/reference/articles/article1059.asp

If you need the Winsock-headers mail me .

To your first question : That is something even DirectPlay has to struggle with, so it can''t be that easy. Something that just came into my mind would be that you check for the rnaapp to be active, well sort of ...

[ Ampaze | turbo.gamedev.net ]

##### Share on other sites
Thanks Ampaze, I''m printing the tutorial right now
And also it would be great if you could send me the headers.

What exactly is the rnaapp? If seen it before in the taskbar manager, but I just thought it was some sort of virus and ran Norton antivirus

Pascalix;

##### Share on other sites
You may want to also look at TBlackUDP, a comp by Lifepower. Very cool stuff...

http://turbo.gamedev.net/BlackUDP.zip

[ turbo | turbo.gamedev.net ]

##### Share on other sites
Thanks for the winsock headers Ampaze. I guess I''ll try and replace the original winsock.pas, that came with Delphi, with winsock2.pas, so that the components will use the newest version.
(if that makes sense)

Any way, I’ve read the article, so now I know the basics of winsock but some of my questions still remain:

I still don’t know how to get the IP (and the name of the computer). When a computer connects to the internet it becomes an equal part of the internet and is assigned an unique IP, that is used to identify it.
So as soon as I’m connected to the internet my computer has an IP, but how do I get it?

Second, I know now, that a connections is accepted with accept(Socket, @Addr, @Len), but can I check which client is about to be connected. For example, how could I check the clients password and username? Because if this can’t be done, than any client could connect to a server (if it knows the port and the IP) and the server would have to disconnect these clients (if they don’t have the right authentication) only after it has already accepted the connection.

Do any of you know of some other ways of finding a computer on the Internet? One way is just to swamp IPs. If you know that the computer has an IP between to static IP than I guess you could just scan all IP in-between, but that takes time. If you know a better way just post it here.

Some sample (pascal) code would really be appreciated.

Pascalix;

##### Share on other sites
Hi,

I did the following to find out my IP:

  var HostEnt : PHostEnt;begin HostEnt := gethostbyname(nil); if HostEnt = nil then ;//errorhandling Memo1.Lines.Add(''IP : '' + inet_ntoa(PInAddr(HostEnt.h_addr_list^)^)); end;

I know it looks "ugly" ... but it works !!!
BTW: This code gives you only the first IP, if there are more than one on the system .

To get the computername use the winapi calls

quote:

any client could connect to a server (if it knows the port and the IP) and the server would have to disconnect these clients (if they don’t have the right authentication) only after it has already accepted the connection.

yes, exactly that way its done

well thats all for now,

[ Ampaze | turbo.gamedev.net ]

##### Share on other sites
Oops, I see I have managed to post an entire post without smiles, so I gotto make up for it

Thanks, I’ll try the code immediately, but I can’t shake off the feeling that some new questions will arise
Well thanks again,
Pascalix;