盛
盛利
Unregistered / Unconfirmed
GUEST, unregistred user!
比如我要开10个线程
创建10个socket,但是消息确是一个,怎么办
WSAAsyncSelect(s, Form1.Handle, WM_CLIENT_READCLOSE, FD_CLOSE xor FD_READ);
这句不好办啊,或者多线程是用的别的方法????
控件的方法不要,请不要贴
const
WM_CLIENT_READ = WM_USER + 103; //自定义windows消息
WM_CLIENT_READCLOSE = WM_USER + 105;
WM_BARICON = WM_USER + 200;
// 初始化SOCKET dll
if WSAStartup($101, TempWSAData) = 1 then
showmessage('WSAStartup Error!');
s := Socket(AF_INET, SOCK_STREAM, 0); //tcp通讯
//Socket创建失败
if (s = INVALID_SOCKET) then
begin
showmessage(inttostr(WSAGetLastError()) + ' Socket创建失败');
CloseSocket(s); exit;
end;
//判断ip地址的格式
ulHostAddress := inet_addr(pchar(serverip));
if (ulHostAddress < 0) then
begin
ulHostAddress := GetHostAddress(serverip);
in_.S_addr := ulHostAddress;
end;
//发送方SockAddr绑定
addr.sin_family := AF_INET;
addr.sin_addr.S_addr := ulHostAddress;
addr.sin_port := htons(port);
if connect(s, addr, sizeof(addr)) <> 0 then
begin
memo1.Lines.Add('connect fail');
end
else
memo1.Lines.Add('connected');
WSAAsyncSelect(s, Form1.Handle, WM_CLIENT_READCLOSE, FD_CLOSE xor FD_READ);
创建10个socket,但是消息确是一个,怎么办
WSAAsyncSelect(s, Form1.Handle, WM_CLIENT_READCLOSE, FD_CLOSE xor FD_READ);
这句不好办啊,或者多线程是用的别的方法????
控件的方法不要,请不要贴
const
WM_CLIENT_READ = WM_USER + 103; //自定义windows消息
WM_CLIENT_READCLOSE = WM_USER + 105;
WM_BARICON = WM_USER + 200;
// 初始化SOCKET dll
if WSAStartup($101, TempWSAData) = 1 then
showmessage('WSAStartup Error!');
s := Socket(AF_INET, SOCK_STREAM, 0); //tcp通讯
//Socket创建失败
if (s = INVALID_SOCKET) then
begin
showmessage(inttostr(WSAGetLastError()) + ' Socket创建失败');
CloseSocket(s); exit;
end;
//判断ip地址的格式
ulHostAddress := inet_addr(pchar(serverip));
if (ulHostAddress < 0) then
begin
ulHostAddress := GetHostAddress(serverip);
in_.S_addr := ulHostAddress;
end;
//发送方SockAddr绑定
addr.sin_family := AF_INET;
addr.sin_addr.S_addr := ulHostAddress;
addr.sin_port := htons(port);
if connect(s, addr, sizeof(addr)) <> 0 then
begin
memo1.Lines.Add('connect fail');
end
else
memo1.Lines.Add('connected');
WSAAsyncSelect(s, Form1.Handle, WM_CLIENT_READCLOSE, FD_CLOSE xor FD_READ);