Y
yvtong
Unregistered / Unconfirmed
GUEST, unregistred user!
局域网聊天程序
服务器端(TserverSocket servertype:stThreadBlocking )
TCharServerThread = class(TServerClientThread)
protected
procedure ClientExecute; override;
end;
procedure TFileServerThread.ClientExecute;
var
Data: array[0..1023] of char;
SocketStream: TWinSocketStream;
senddata:ansistring;
revData:string;
begin
while not Terminated and ClientSocket.Connected do
try
SocketStream := TWinSocketStream.Create(ClientSocket, 20);
try
FillChar(Data, SizeOf(Data), 0);
SocketStream.Read(Data, SizeOf(Data));
revData:=data;
if revData<>'' then
SendMessage(Form1.Listbox1.Handle, LB_ADDSTRING, 0, Integer(PChar(revdata))); //在LISTBOX中显示
finally
SocketStream.Free;
end;
except
HandleException;
end;
end;
客户端TclientSocket clienttype:ctNonBlocking)
现在功能:接受多个客户端的消息
问题:如何向不同的客户端随时发送消息
服务器端(TserverSocket servertype:stThreadBlocking )
TCharServerThread = class(TServerClientThread)
protected
procedure ClientExecute; override;
end;
procedure TFileServerThread.ClientExecute;
var
Data: array[0..1023] of char;
SocketStream: TWinSocketStream;
senddata:ansistring;
revData:string;
begin
while not Terminated and ClientSocket.Connected do
try
SocketStream := TWinSocketStream.Create(ClientSocket, 20);
try
FillChar(Data, SizeOf(Data), 0);
SocketStream.Read(Data, SizeOf(Data));
revData:=data;
if revData<>'' then
SendMessage(Form1.Listbox1.Handle, LB_ADDSTRING, 0, Integer(PChar(revdata))); //在LISTBOX中显示
finally
SocketStream.Free;
end;
except
HandleException;
end;
end;
客户端TclientSocket clienttype:ctNonBlocking)
现在功能:接受多个客户端的消息
问题:如何向不同的客户端随时发送消息