M
meijingpengwork
Unregistered / Unconfirmed
GUEST, unregistred user!
procedure TForm1.BtnconnectClick(Sender: TObject);
var
ca : sockaddr_in;
hostaddr : u_long;
begin
Client := socket(PF_INET,SOCK_STREAM,IPPROTO_IP);
if Client = INVALID_SOCKET then
begin
statusbar1.SimpleText :='为连接远端服务器创建SOCK错误';
EXIT;
end;
ca.sin_family := PF_INET;
ca.sin_port := htons(strtoint(trim(EdtPort.Text)));
hostaddr := inet_addr(pchar(trim(EdtIP.Text)));
if hostaddr = -1 then
begin
statusbar1.SimpleText := '主机IP错误';
exit;
end
else
begin
ca.sin_addr.S_addr := hostaddr;
end;
//连接服务器
if connect(Client,ca,sizeof(ca)) <>0 then
begin
statusbar1.SimpleText := '连接SOCKET错误';
exit;
end
else
begin
statusbar1.SimpleText := '连接SOCKET--success';
end;
end;
运行到if connect(Client,ca,sizeof(ca)) <>0 then 就错了 connect返回值是-1
服务器是本机,端口是8080
CONNECT是不是参错错了,该怎么设
var
ca : sockaddr_in;
hostaddr : u_long;
begin
Client := socket(PF_INET,SOCK_STREAM,IPPROTO_IP);
if Client = INVALID_SOCKET then
begin
statusbar1.SimpleText :='为连接远端服务器创建SOCK错误';
EXIT;
end;
ca.sin_family := PF_INET;
ca.sin_port := htons(strtoint(trim(EdtPort.Text)));
hostaddr := inet_addr(pchar(trim(EdtIP.Text)));
if hostaddr = -1 then
begin
statusbar1.SimpleText := '主机IP错误';
exit;
end
else
begin
ca.sin_addr.S_addr := hostaddr;
end;
//连接服务器
if connect(Client,ca,sizeof(ca)) <>0 then
begin
statusbar1.SimpleText := '连接SOCKET错误';
exit;
end
else
begin
statusbar1.SimpleText := '连接SOCKET--success';
end;
end;
运行到if connect(Client,ca,sizeof(ca)) <>0 then 就错了 connect返回值是-1
服务器是本机,端口是8080
CONNECT是不是参错错了,该怎么设