环境:DELPHI XE2 INDY10
目标:HTTP数据转发,把电脑A的hosts里加入192.168.0.2 www.csdn.net,然后在电脑B(IP192.168.0.2)上运行本程序,接收电脑A的请求,再通过网络把请求发给www.baidu.com的IP.最后,把返回数据再传给电脑A.打算使用idtcpserver和idtcpclient.原型大概写了,但具体使用上有问题.procedure TForm1.IdTCPServer1Execute(AContext: TIdContext);
var
idc:tidtcpclient;
Buffer,buffer2: TidBytes;
i,j:integer;
begin
memo1.lines.add(acontext.Binding.PeerIP);
idc:=tidtcpclient.Create(nil);
idc.Host:=11.22.33.44;//HTTP目标IP
idc.Port:=80;
idc.Connect;
AContext.Connection.iohandler.ReadBytes(buffer,i);//先取得A要转发的数据 idc.IOHandler.Write(buffer,i);//转发到目标
idc.IOHandler.ReadBytes(buffer2,j);//取得返回数据 AContext.Connection.iohandler.Write(buffer2,j);//传回给A
acontext.Connection.Socket.Close;
idc.Socket.Close;
idc.Free;
end;
因为不知道具体方法,函数和参数都有错误,请帮忙完善.
目标:HTTP数据转发,把电脑A的hosts里加入192.168.0.2 www.csdn.net,然后在电脑B(IP192.168.0.2)上运行本程序,接收电脑A的请求,再通过网络把请求发给www.baidu.com的IP.最后,把返回数据再传给电脑A.打算使用idtcpserver和idtcpclient.原型大概写了,但具体使用上有问题.procedure TForm1.IdTCPServer1Execute(AContext: TIdContext);
var
idc:tidtcpclient;
Buffer,buffer2: TidBytes;
i,j:integer;
begin
memo1.lines.add(acontext.Binding.PeerIP);
idc:=tidtcpclient.Create(nil);
idc.Host:=11.22.33.44;//HTTP目标IP
idc.Port:=80;
idc.Connect;
AContext.Connection.iohandler.ReadBytes(buffer,i);//先取得A要转发的数据 idc.IOHandler.Write(buffer,i);//转发到目标
idc.IOHandler.ReadBytes(buffer2,j);//取得返回数据 AContext.Connection.iohandler.Write(buffer2,j);//传回给A
acontext.Connection.Socket.Close;
idc.Socket.Close;
idc.Free;
end;
因为不知道具体方法,函数和参数都有错误,请帮忙完善.
解决方案 »
- 送分的 delphi中将string转化为array
- cxgridTableView关于ButtonEdit的问题
- edit怎么样判断扫描枪扫描还是键盘输入。(100分相送)
- 一个小问题。大家快来解决下,在线等
- 请问怎么样才能将同一编号的记录打印在一张报表上?
- OK
- ADO如何保存ASC码大于128的字符?
- 请求帮忙,很急!
- 声明:我发现我给自己加过一次分 但那纯属误操作(今天看了老鱼同志的帖子才注意到) 特向各位道歉 希望斑竹能把分给扣掉 证据:http://www.csdn.net/expert/topic/386/386512.shtm
- 怪了!Tadoconnection动态打开连接不行了
- delphitreeview双击事件,怎么是只有双击子树有效
- 菜鸟求助。
主要是发送和接收的4段怎么处理.
上面的ReadBytes函数容易卡死,
改成下面的就可以工作,但只能中转字符串等,如果是其它图片等压缩数据就不行了.var msg:ansistring;
AContext.Connection.iohandler.Readln(msg);//先取得A要转发的数据
idc.IOHandler.Writeln(msg);//转发到目标
idc.IOHandler.Readln(msg);//取得返回数据
AContext.Connection.iohandler.Writeln(msg);//传回给A