寻找详细一点介绍Delphi做的聊天程序(多人)的资料,没有的话符合下面介绍的也行啊!(50分)

  • 主题发起人 主题发起人 jiajiapai
  • 开始时间 开始时间
J

jiajiapai

Unregistered / Unconfirmed
GUEST, unregistred user!
我学Delphi 时间不长,现在想做一个服务器端+多个客户端,客户端可以通过通过服务器端提交数据,服务器端可以从数据库搜索一定的数据然后再发给需要的一个或多个客户端。
我觉得跟聊天室的功能差不多!
 
如果学Delphi事件不长有些困难
看一下Delphi中关于COM/DCOM的相关知识吧
 
unit Chatmain;

interface

uses
Classes, QControls, QStdCtrls, QExtCtrls, QButtons, QForms, Sockets;


type
TForm1 = class(TForm)
memRecv: TMemo;
Panel1: TPanel;
memSend: TMemo;
Panel2: TPanel;
btnSend: TButton;
Panel3: TPanel;
Label1: TLabel;
edtRemoteHost: TEdit;
Label2: TLabel;
edtRemotePort: TEdit;
Label3: TLabel;
edtLocalPort: TEdit;
btnActivateServer: TButton;
TcpClient1: TTcpClient;
TcpServer1: TTcpServer;
procedure btnSendClick(Sender: TObject);
procedure TcpServer1Accept(sender: TObject;
ClientSocket: TCustomIpClient);
procedure btnActivateServerClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

// you must create your own thread to synch
// writing to a gui component
TClientDataThread = class(TThread)
private
public
ListBuffer :TStringList;
TargetList :TStrings;
procedure synchAddDataToControl;
constructor Create(CreateSuspended: Boolean);
procedure Execute; override;
procedure Terminate;
end;

var
Form1: TForm1;
//DataThread: TClientDataThread;

implementation

{$R *.xfm}

//------------- TClientDataThread impl -----------------------------------------
constructor TClientDataThread.Create(CreateSuspended: Boolean);
begin
inherited Create(CreateSuspended);
FreeOnTerminate := true;
ListBuffer := TStringList.Create;
end;

procedure TClientDataThread.Terminate;
begin
ListBuffer.Free;
inherited;
end;

procedure TClientDataThread.Execute;
begin
Synchronize(synchAddDataToControl);
end;

procedure TClientDataThread.synchAddDataToControl;
begin
TargetList.AddStrings(ListBuffer);
end;
//------------- end TClientDataThread impl -------------------------------------


procedure TForm1.btnActivateServerClick(Sender: TObject);
begin
TcpServer1.LocalPort := edtLocalPort.Text;
TcpServer1.Active := True;
end;

procedure TForm1.btnSendClick(Sender: TObject);
var
I: Integer;
begin
TcpClient1.RemoteHost := edtRemoteHost.Text;
TcpClient1.RemotePort := edtRemotePort.Text;
try
if TcpClient1.Connect then
for I := 0 to memSend.Lines.Count - 1 do
TcpClient1.Sendln(memSend.Lines);
finally
TcpClient1.Disconnect;
end;
end;

procedure TForm1.TcpServer1Accept(sender: TObject;
ClientSocket: TCustomIpClient);
var
s: string;
DataThread: TClientDataThread;
begin
// create thread
DataThread:= TClientDataThread.Create(true);
// set the TagetList to the gui list that you
// with to synch with.
DataThread.TargetList := memRecv.lines;

// Load the Threads ListBuffer
DataThread.ListBuffer.Add('*** Connection Accepted ***');
DataThread.ListBuffer.Add('Remote Host: ' + ClientSocket.LookupHostName(ClientSocket.RemoteHost) +
' (' + ClientSocket.RemoteHost + ')');
DataThread.ListBuffer.Add('===== Begin message =====');
s := ClientSocket.Receiveln;
while s <> '' do
begin
DataThread.ListBuffer.Add(s);
s := ClientSocket.Receiveln;
end;
DataThread.ListBuffer.Add('===== End of message =====');

// Call Resume which will execute and synch the
// ListBuffer with the TargetList
DataThread.Resume;

end;

end.
 
没有注释阿
我就是想做一个服务器端和多个客户端,多个监测端,客户端将一条自己需要的信息传给服务器,服务器再写到数据库中,检测端如果通过其它途径检测到某个客户端需要的信息,及时发给服务器,然后服务器再通知需要的客户端。我觉得跟聊天差不多!
我先在就是服务器接受和转发信息那里不太懂,具体怎么知道接受的是哪个客户端的信息,而且同时又2个客户端发给服务器信息怎么处理?
 
这个是用TTcpClient和TcpServer这两个控件来做的。你在DELPHI安装目录里面的Demos/Internet/NetChat可找到,我的安装目录是以下。你用DELPHI打开里面的工程文件,就可以看清楚了。
C:/Program Files/Borland/Delphi7/Demos/Internet/NetChat
 
用UDP协议怎么做啊>
 
有报酬的话,我可以直接给你写一个!~
功能比较全的那种!
 
我要的其实不是成品,我是想明白是怎么做的
 
后退
顶部