客户端用这个发送消息可以吗?如果可以,服务端如何接收啊?function SendInfo(Server:String;Port:integer):String;
var
len,s:integer;
name:sockaddr_in;
he:PHostEnt;
buf:array[0..1023]of char;
str,data:string;
wsd:WSADATA;
i:integer;
begin
WSAStartup($101,wsd);
s:=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
he:=gethostbyname(PChar(Server));
if he=nil then
Raise Exception.Create('使用Sock连接异常或是指定服务器有误!'); FillChar(name,sizeof(name),0);
name.sin_family:=AF_INET;
name.sin_port:=htons(Port);
name.sin_addr.S_addr:=PDWORD(PDWORD(he.h_addr)^)^;
connect(s,name,sizeof(name));
str := '123';
send(s,PChar(str)^,Length(str),0); closesocket(s);
WSACleanup();
Result := data;
end;
var
len,s:integer;
name:sockaddr_in;
he:PHostEnt;
buf:array[0..1023]of char;
str,data:string;
wsd:WSADATA;
i:integer;
begin
WSAStartup($101,wsd);
s:=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
he:=gethostbyname(PChar(Server));
if he=nil then
Raise Exception.Create('使用Sock连接异常或是指定服务器有误!'); FillChar(name,sizeof(name),0);
name.sin_family:=AF_INET;
name.sin_port:=htons(Port);
name.sin_addr.S_addr:=PDWORD(PDWORD(he.h_addr)^)^;
connect(s,name,sizeof(name));
str := '123';
send(s,PChar(str)^,Length(str),0); closesocket(s);
WSACleanup();
Result := data;
end;
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货