我用的控件是INDY server 中的IdTCPServer1.和Internet中的TcpServer1控件
我写了如下代码:
procedure TForm1.SetPortExecute(Sender: TObject);
begin
//设置TCP服务器的端口号;
try
self.IdTCPServer1.DefaultPort := StrToInt(Edit1.Text);
Except
Application.MessageBox('输入有误,请重新输入!','【★】错误',
Mb_ok + MB_ICONError);
Exit;
end;
//打开TCP服务器,开始监听客户的请求;
self.IdTCPServer1.Active := true;procedure TForm1.IdTCPServer1Execute(AThread: TIdPeerThread);
var
Infor : string;
begin
if (not AThread.Terminated) and (AThread.Connection.Connected) then
begin
Button1.Enabled := false;
self.TcpServer1.LocalPort := '9100';
self.TcpServer1.Active := true;
self.TreeView1.Items.Add(nil,self.TcpServer1.RemoteHost);
self.TreeView1.Items.Add(nil,self.TcpServer1.RemotePort);
try
AThread.Connection.ReadBuff(Infor,sizeof(Infor));
self.Memo1.Lines.Add('发来的信息:' + Infor + #13#10);
Except
Application.MessageBox('读取信息失败!','错误',MB_Ok + MB_ICONError);
self.IdTCPServer1.Active := false;
end; end;
end;
但是不能实现我的帮助主题,请高手指点,急!急!急!急!
我写了如下代码:
procedure TForm1.SetPortExecute(Sender: TObject);
begin
//设置TCP服务器的端口号;
try
self.IdTCPServer1.DefaultPort := StrToInt(Edit1.Text);
Except
Application.MessageBox('输入有误,请重新输入!','【★】错误',
Mb_ok + MB_ICONError);
Exit;
end;
//打开TCP服务器,开始监听客户的请求;
self.IdTCPServer1.Active := true;procedure TForm1.IdTCPServer1Execute(AThread: TIdPeerThread);
var
Infor : string;
begin
if (not AThread.Terminated) and (AThread.Connection.Connected) then
begin
Button1.Enabled := false;
self.TcpServer1.LocalPort := '9100';
self.TcpServer1.Active := true;
self.TreeView1.Items.Add(nil,self.TcpServer1.RemoteHost);
self.TreeView1.Items.Add(nil,self.TcpServer1.RemotePort);
try
AThread.Connection.ReadBuff(Infor,sizeof(Infor));
self.Memo1.Lines.Add('发来的信息:' + Infor + #13#10);
Except
Application.MessageBox('读取信息失败!','错误',MB_Ok + MB_ICONError);
self.IdTCPServer1.Active := false;
end; end;
end;
但是不能实现我的帮助主题,请高手指点,急!急!急!急!
var
msg:String;
begin
athread.Connection.Socket.Binding.PeerIP; //ip
athread.Connection.Socket.Binding.PeerPort; //port
Msg:= athread.Connection.CurrentReadBuffer;//接收发送来的消息
end;end.