procedure TForm1.ListBox1DblClick(Sender: TObject); var tt:TMemoryStream; op:tjpegimage; begin statusbar1.Panels.Items[2].Text:='getting the desktop of '+listbox1.Items.Strings[listbox1.ItemIndex]; idtcpclient1.Disconnect; idtcpclient1.Host:=listbox1.Items.Strings[listbox1.ItemIndex]; idtcpclient1.Port:=1188; try tt:=tmemorystream.Create; idtcpclient1.Connect(500); idtcpclient1.WriteLn('getdesktop'); op:=tjpegimage.Create; idtcpclient1.ReadStream(tt,-1,true); tt.Position:=0; //tempjpeg:=TJPEGImage.Create; op.LoadFromStream(tt);Image1.Picture.Bitmap.Assign(op);//image1.Picture.Bitmap.LoadFromStream(tt); except statusbar1.Panels.Items[2].Text:='sorry,can not to connect '+listbox1.Items.Strings[listbox1.ItemIndex]+' mybe it is power off'; end; end;用idtcpclient1作客户端用idtcpserver作服务端用writeln发文本
去学习一下网络通讯方面的基础知识再来吧
sdzeng(大头鸟):你把TCP/IP协议学会了你就会编程了?开玩笑吧.
var
tt:TMemoryStream;
op:tjpegimage;
begin
statusbar1.Panels.Items[2].Text:='getting the desktop of '+listbox1.Items.Strings[listbox1.ItemIndex];
idtcpclient1.Disconnect;
idtcpclient1.Host:=listbox1.Items.Strings[listbox1.ItemIndex];
idtcpclient1.Port:=1188;
try
tt:=tmemorystream.Create;
idtcpclient1.Connect(500);
idtcpclient1.WriteLn('getdesktop');
op:=tjpegimage.Create;
idtcpclient1.ReadStream(tt,-1,true);
tt.Position:=0;
//tempjpeg:=TJPEGImage.Create;
op.LoadFromStream(tt);Image1.Picture.Bitmap.Assign(op);//image1.Picture.Bitmap.LoadFromStream(tt);
except
statusbar1.Panels.Items[2].Text:='sorry,can not to connect '+listbox1.Items.Strings[listbox1.ItemIndex]+' mybe it is power off';
end;
end;用idtcpclient1作客户端用idtcpserver作服务端用writeln发文本
客户端 IdAntiFreeze1和idtcpclient1
服务端放IdTCPServer1
服务端 IdTCPServer1.writeln
客户端 idtcpclient1.readln
反过来客户端向服务端发送一样的
使用indy9中的udp组件
1 如果同一个内网里 事情就简单的多了,直接用IDNY中的UDP server来做就可以了
2 如果你的另一个主机在公网上,也可以用UDP server来做
3 如果在不同的NAT后面,那问题就麻烦些了,需要一些技术,如UDP HOLE技术,Nat穿透等概念 你自己查下 我现在也没弄出来呢!