🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #4303

Re: open a port in Windows...

#4303
From: Remy Lebeau (TeamB)
Date: Wed, 08 Feb 2006 19:07
28 lines
1955 bytes
"Malm32" <antreas7@bluebottle.com> wrote in message
news:43e9f382$1@newsgroups.borland.com...

> Is there any way to open a port in windows

I assume that you are referring to a socket port?  If so, then simply create
a new socket via the socket() function, bind it to a local IP/port via the
bind() function, listen on it via the listen() function, and read from via
the recv() function.  Refer to the Win32 API documentation for more details.

> or find out which ports are open.

The easiest way to do that is to loop through all possible port numbers
(1-65535) attempting to bind to each one and see which ones succeed or fail.

Alternatively, there are OS hooks available that can retreive the
information more accurately.  Refer to
http://www.sysinternals.com/Utilities/TcpView.html for details.

> I want to know that so as to use my program as a server.

Just pick any port number and use it in your code.  Best would be if you let
the user tell your program which port number to use dynamically.  If the
socket fails when you try to open it, you can tell your user about it.


Gambit
Technical Details
Message-ID: <43ea40cb$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news4.google.com!news2.volia.net!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <43e9f382$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,2576a1d1dc3092
X-Google-Attributes: gid10cc67,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Remy Lebeau \(TeamB\)" <no.spam@no.spam.com>
Newsgroups: borland.public.cppbuilder.nativeapi
References: <43e9f382$1@newsgroups.borland.com>
Subject: Re: open a port in Windows...
Date: Wed, 8 Feb 2006 11:07:32 -0800
Lines: 30
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1409
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409
NNTP-Posting-Host: 68.69.17.41
Message-ID: <43ea40cb$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1139425483 68.69.17.41 (8 Feb 2006 11:04:43 -0700)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news4.google.com!news2.volia.net!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail