Link to home
Start Free TrialLog in
Avatar of Peter Kiers
Peter KiersFlag for Netherlands

asked on

How can i set a port number

Dear Experts,

In my programm I have put 2 edit-boxes, where the user must specify the IP-address/Hostname
and the Port number to make a connection to a server. The IP-address/Hostname editbox is finished. Only I have a hard time to find where in the procedure MakeConnect the port number
is specified!

I have put a partial code of the procedure MakeConnect, because it's a long procedure.

procedure MakeConnect;
var
 usPort: u_short;         <=============
...
 usPort := pServAddr^.s_port;          <===============
 RemoteAddr.sin_family := AF_INET;
 RemoteAddr.sin_addr.s_addr := ina.s_addr;
 RemoteAddr.sin_port := usPort;         <==============
 psaddr := Pointer(@RemoteAddr);

The port 23 is specified in this code, because when i look at my logging i see this:

TCP Started.
Socket opened OK.
Foreign host name: 145.70.16.5
    Address type: 2
    Address length: 4
    Foreign host address: 145.70.16.5
Local host name: cp557259-a
    Address type: 2
    Address length: 4
    Local host address: 192.168.1.2
Bind successful
Remote Service Info.:
    Name: telnet
    Port: 23              <===========
Connect error: 10060
TCP Ended.

How can i when the user enter a port number in the edit-box pass it on to the
MakeConnect-procedure?

Greetings,

Peter Kiers
Avatar of MerijnB
MerijnB
Flag of Netherlands image

usPort := pServAddr^.s_port;          <===============
 

what is pServAddr and where is it filled in?
Avatar of Peter Kiers

ASKER

Procedure MakeConnect;
I have put here al the lines with pServAddr:

var
  pServAddr: PServEnt;   <== is also declared
        .....
          pServAddr := getservbyname('telnet', 'tcp');
          if pServAddr <> nil then
        .....
            usPort := pServAddr^.s_port;
            RemoteAddr.sin_family := AF_INET;
            RemoteAddr.sin_addr.s_addr := ina.s_addr;
            RemoteAddr.sin_port := usPort;
        .....

Peter          
I have put the complete procedure on my site

http://members.home.nl/peterkiers/
(click on the floppy-disk underneath the Under Construction bar)

I hope this makes it easer...

P.
ASKER CERTIFIED SOLUTION
Avatar of MerijnB
MerijnB
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
The portnumber that the user enters in a edit-box
is stored in a variable called ConnectPortName.

var
 usPort: u_short;        
...
 usPort := //what do i have to put here???
 RemoteAddr.sin_family := AF_INET;
 RemoteAddr.sin_addr.s_addr := ina.s_addr;
 RemoteAddr.sin_port := usPort;        
 psaddr := Pointer(@RemoteAddr);
end;
Thanks i have got it.

Peter Kiers