Home > Back-end >  Day in Delphi port multiplexing problem
Day in Delphi port multiplexing problem

Time:09-25

Hello, I want to ask you a question, in the Delphi realize the reuse of port
I found a piece of code on the net
Var
PEnt: PHostEnt;
The device: the string;
//port multiplexing
Sobinyshuai: bool;
MyIP: PChar;
PORT: integer;
ServerSocket: TSocket;
SockAddrIn: TSockAddrIn;
WSAData: TWSAData;
The begin
MyIP:='192.168.2.107';
PORT:=1980;
SobinyShuai:=true;
WSAStartUp (MakeWord (1, 1), WSAData);
ServerSocket=WSASocket (AF_INET SOCK_STREAM, IPPROTO_TCP, NIL, 0, 0). {to build a TCP socket,}
The setsockopt (ServerSocket, SOL_SOCKET, SO_REUSEADDR, @ sobinyshuai, sizeof (sobinyshuai)); {allows port reuse}
SockAddrIn. Sin_family:=AF_INET;
SockAddrIn. Sin_addr. S_addr:=inet_addr (myIP);
SockAddrIn. Sin_port:=htons (Port); {set the connection port}
Bind (ServerSocket SockAddrIn, SizeOf (SockAddrIn)); {set ServerSocket properties, should understand it}
Listen (ServerSocket, 1); {set up to monitor, wait for connection, only Accept a connection before Accept}

end;

This code can realize the use of port, but I tried without success
I want to ask, in the code above myIP refers to the IP address of the network IP address or the IP address of the networks outside
The inside of the PORT PORT is batch to native PORT?
And it is the Lord is the code to add in the end what position,
If you have this aspect of the code can send me a thank you

CodePudding user response:

192.168, this is the Intranet, actually has nothing to do with inside and outside, as long as IP access
  • Related