我正在做一个局域网聊天工具,客户端和服务器连接正常,但是客户端之间连接不正常..我用的是tcpserver和tcpclient来负责客户端之间的通信.代码如下procedure TFormChat.ButtonSendClick(Sender: TObject);//发送数据begin
TcpServer1.LocalPort:='8088';
TcpServer1.Active:=True; TcpClient1.RemoteHost:='192.168.1.100';//因为是2台机器之间测试,所以我直接写出了对方的ip
TcpClient1.RemotePort:='8088';
try
if TcpServer1.Connect=True then
begin
ShowMessage('我已经和朋友连接上了');
Tcpclient1.Sendln(edit1.Text);
memo1.Lines.Add('remote host:'+self.IdIPWatch1.LocalName+'('+self.IdIPWatch1.LocalIP+')');
memo1.Lines.Add(edit1.Text);
memo1.Lines.Clear;
end
else ShowMessage('我已经和朋友连接上了1111111');
finally
tcpclient1.Disconnect;
end;
end;事实上没有连接上,我郁闷,请大家帮我看看
TcpServer1.LocalPort:='8088';
TcpServer1.Active:=True; TcpClient1.RemoteHost:='192.168.1.100';//因为是2台机器之间测试,所以我直接写出了对方的ip
TcpClient1.RemotePort:='8088';
try
if TcpServer1.Connect=True then
begin
ShowMessage('我已经和朋友连接上了');
Tcpclient1.Sendln(edit1.Text);
memo1.Lines.Add('remote host:'+self.IdIPWatch1.LocalName+'('+self.IdIPWatch1.LocalIP+')');
memo1.Lines.Add(edit1.Text);
memo1.Lines.Clear;
end
else ShowMessage('我已经和朋友连接上了1111111');
finally
tcpclient1.Disconnect;
end;
end;事实上没有连接上,我郁闷,请大家帮我看看
看看Demo,你知道为什么了!
应该改成:
if Tcpclient1.Connect then
begin
ShowMessage('我已经和朋友连接上了');
end
else
begin
ShowMessage('没有连接上');
end;
和一个tcpserver在聊天界面里。。
那一句应该是我复制上来的时候弄错了,我的源代码里写的是tcpclient,
况且写tcpserver.connect也编译不过去