完成端口客户端出错,怎么改! ( 积分: 50 )

  • 主题发起人 主题发起人 fire.bruin
  • 开始时间 开始时间
F

fire.bruin

Unregistered / Unconfirmed
GUEST, unregistred user!
......

const
ServerIP = '192.168.0.1';
ServerPORT = 51937;
.....

procedure TForm_into.FormCreate(Sender: TObject);
Var
wsaData: TWSAData;
ListenSocket: TSOCKET;
InternetAddr: TSockAddrin;
tmpPacket: array [0..1023] of byte;

begin
WSAStartup(makeword(2, 0), wsaData);
ListenSocket := WSASocket(AF_INET, SOCK_STREAM, 0, nil, 0, WSA_FLAG_OVERLAPPED);
InternetAddr.sin_family := AF_INET;
InternetAddr.sin_addr.s_addr := inet_addr(ServerIP);
InternetAddr.sin_port := htons(ServerPORT);
//下面一句总是报错 Incompatible types:'TSockAddrIn' and 'PSockAddr'
connect(ListenSocket, InternetAddr, sizeof(InternetAddr));
.......

end
 
......

const
ServerIP = '192.168.0.1';
ServerPORT = 51937;
.....

procedure TForm_into.FormCreate(Sender: TObject);
Var
wsaData: TWSAData;
ListenSocket: TSOCKET;
InternetAddr: TSockAddrin;
tmpPacket: array [0..1023] of byte;

begin
WSAStartup(makeword(2, 0), wsaData);
ListenSocket := WSASocket(AF_INET, SOCK_STREAM, 0, nil, 0, WSA_FLAG_OVERLAPPED);
InternetAddr.sin_family := AF_INET;
InternetAddr.sin_addr.s_addr := inet_addr(ServerIP);
InternetAddr.sin_port := htons(ServerPORT);
//下面一句总是报错 Incompatible types:'TSockAddrIn' and 'PSockAddr'
connect(ListenSocket, InternetAddr, sizeof(InternetAddr));
.......

end
 
connect(ListenSocket, @InternetAddr, sizeof(InternetAddr));
 
接受答案了.
 
后退
顶部