如果您想了解delphi–使用IndyServer的多个绑定作为单独的套接字?的相关知识,那么本文是一篇不可错过的文章,我们将对delphi连接多个数据库进行全面详尽的解释,并且为您提供关于andro
如果您想了解delphi – 使用Indy Server的多个绑定作为单独的套接字?的相关知识,那么本文是一篇不可错过的文章,我们将对delphi连接多个数据库进行全面详尽的解释,并且为您提供关于android – 保护VpnService中的套接字、Delphi 2009,Indy 10,TIdTCPServer.OnExecute,如何获取InputBuffer中的所有字节、Delphi 7 中使用Indy创建独立的 Web Services/SOAP 服务器(一)、Delphi 7 中使用Indy创建独立的 Web Services/SOAP 服务器(三)的有价值的信息。
本文目录一览:- delphi – 使用Indy Server的多个绑定作为单独的套接字?(delphi连接多个数据库)
- android – 保护VpnService中的套接字
- Delphi 2009,Indy 10,TIdTCPServer.OnExecute,如何获取InputBuffer中的所有字节
- Delphi 7 中使用Indy创建独立的 Web Services/SOAP 服务器(一)
- Delphi 7 中使用Indy创建独立的 Web Services/SOAP 服务器(三)
delphi – 使用Indy Server的多个绑定作为单独的套接字?(delphi连接多个数据库)
我正在重建我的旧系统,它使用ScktComps的旧式TServerSocket和TClientSocket组件,并使用Indy TIdTcpserver和TIdTCPClient重新组装.旧系统实际上由每个端口上的3个完全不同的服务器/客户端套接字组成,每个套接字用于不同的目的,并且一起工作 – 类似于FTP如何使用一个套接字用于二进制数据而另一个套接字用于命令.
是否可以使用这些绑定模拟同一组件中的三个独立的服务器/客户端套接字?如果我只能声明一个绑定了3个端口的服务器套接字,并且在客户端上连接到服务器上的3个不同端口,那就太棒了.我想做的就是不再需要创建3个独立的服务器/客户端套接字组件并将它们组合成一个组件.
解决方法
在TIdTcpserver.Bindings集合中创建3个条目,每个条目对应要侦听的每个本地IP /端口,其中TIdSocketHandle.Port属性将等效于TServerSocket.Port属性. TServerSocket本身不支持绑定到特定IP(尽管可以通过一些手动工作完成),但TIdSocketHandle.IP属性用于此目的,其中空字符串与INADDR_ANY等效.
在TIdcpserver.OnConnect,TIdcpserver.Ondisconnect和TIdcpserver.OnExecute事件中,您可以使用TIdContext.Binding.IP和TIdContext.Binding.Port属性来区分调用套接字连接的绑定.
这种情况的一个常见用途是支持不同端口上的SSL和非SSL客户端,例如POP3和SMTP等协议,这些协议支持不同端口上的隐式和显式SSL / TLS. TIdHTTPServer执行此操作以在单个服务器上支持HTTP和HTTPS URL(您可以使用TIdHTTPServer.OnQuerySSLPort来自定义哪些端口使用SSL / TLS而不是使用SSL / TLS).
例如:
procedure TForm1.StartButtonCick(Sender: TObject); begin IdTcpserver1.Active := False; IdTcpserver1.Bindings.Clear; with IdTcpserver1.Bindings.Add do begin IP := ...; Port := 2000; end; with IdTcpserver1.Bindings.Add do begin IP := ...; Port := 2001; end; with IdTcpserver1.Bindings.Add do begin IP := ...; Port := 2002; end; IdTcpserver1.Active := True; end; procedure TForm1.IdTcpserver1Execute(AContext: TIdContext); begin case AContext.Binding.Port of 2000: begin // do something... end; 2001: begin // do something else... end; 2002: begin // do yet something else ... end; end; end;
android – 保护VpnService中的套接字
我已经明白,最后一点由VpnService.protect()方便,并尝试实现如下:
Socket socket = new Socket(); vpnService.protect(socket); socket.connect(new InetSocketAddress( header.getDestinationAddress(),// From my IP datagram header body.getDestinationPort())); // From the TCP datagram header
不幸的是,这种方法导致了VPN接口的环回.
而上面的代码将简单地阻止并最终超时,我通过从单独的线程调用Socket.connect(InetSocketAddress)来观察环回.该连接直接返回到我的VpnService的输入流中,该过程重复.
不用说,这会导致循环.我得到这样的感觉,原因是在创建套接字时(随后调用VpnService.protect(Socket)),我还没有设置目标IP&港口
这似乎确实是这样,因为在我的VpnService实现中覆盖VpnService.protect(Socket)和VpnService.protect(int),并且在两种情况下调用supers都返回false.
如何正确保护套接字连接?
解决方法
Socket socket = SocketChannel.open().socket(); if ((null != socket) && (null != vpnService)) { vpnService.protect(socket); } socket.connect(...);
新的Socket()没有有效的文件描述符,所以它不能被保护.
Delphi 2009,Indy 10,TIdTCPServer.OnExecute,如何获取InputBuffer中的所有字节
procedure TFormMain.IdTcpserverExecute(AContext: TIdContext); var RxBufStr: UTF8String; RxBufSize: Integer; begin if AContext.Connection.IOHandler.Readable then begin RxBufSize := AContext.Connection.IOHandler.InputBuffer.Size; if RxBufSize > 0 then begin SetLength(RxBufStr,RxBufSize); AContext.Connection.IOHandler.ReadBytes(TBytes(RxBufStr),RxBufSize,False); end; end; end;
AContext.Connection.IOHandler.InputBuffer.Size似乎不可靠并经常返回0,但是在下次运行时,OnExecute它将获取正确的字节数,但为时已晚.
基本上我希望能够只获取所有数据,将其填充到UTF8String(不是Unicode字符串),然后解析一个特殊的标记.所以我没有标题,消息长度可变.似乎Indy 10 IOHandlers没有为此设置,或者我只是错误地使用它.
做一些像传递一定大小的缓冲区,尽可能多地填充它并返回实际填充的字节数然后继续运行(如果还有更多)会很好.
除了TIdSchedulerOfFiber的状态之外,这看起来非常有趣,它有用吗?有人用吗?我注意到它不在Delphi 2009的标准安装中.
更新:我发现Msg:= AContext.Connection.IOHandler.ReadLn(#0,enUTF8);哪个有效,但我仍然想知道上述问题的答案,是因为它是基于阻止IO吗?这使得TIdSchedulerOfFiber更加热衷于此.
解决方法
procedure TFormMain.IdTcpserverExecute(AContext: TIdContext); var RxBuf: TIdBytes; begin RxBuf := nil; with AContext.Connection.IOHandler do begin CheckForDataOnSource(10); if not InputBufferIsEmpty then begin InputBuffer.ExtractToBytes(RxBuf); // process RxBuf as needed... end; end; end;
或者:
procedure TFormMain.IdTcpserverExecute(AContext: TIdContext); var RxBufStr: String; // not UTF8String begin with AContext.Connection.IOHandler do begin CheckForDataOnSource(10); if not InputBufferIsEmpty then begin RxBufStr := InputBuffer.Extract(-1,enUtf8); // Alternatively to above,you can set the // InputBuffer.Encoding property to enUtf8 // beforehand,and then call TIdBuffer.Extract() // without any parameters. // // Or,set the IOHandler.DefStringEncoding // property to enUtf8 beforehand,and then // call TIdioHandler.InputBufferAsstring() // process RxBufStr as needed... end; end; end;
至于TIdSchedulerOfFiber – 此时SuperCore包实际上已经死了.它还没有在很长一段时间内完成,也没有与最新的Indy 10架构保持同步.我们可能会在以后尝试复活它,但它不在我们不久的将来的计划中.
Delphi 7 中使用Indy创建独立的 Web Services/SOAP 服务器(一)
总结
以上是小编为你收集整理的Delphi 7 中使用Indy创建独立的 Web Services/SOAP 服务器(一)全部内容。
如果觉得小编网站内容还不错,欢迎将小编网站推荐给好友。
Delphi 7 中使用Indy创建独立的 Web Services/SOAP 服务器(三)
总结
以上是小编为你收集整理的Delphi 7 中使用Indy创建独立的 Web Services/SOAP 服务器(三)全部内容。
如果觉得小编网站内容还不错,欢迎将小编网站推荐给好友。
关于delphi – 使用Indy Server的多个绑定作为单独的套接字?和delphi连接多个数据库的介绍现已完结,谢谢您的耐心阅读,如果想了解更多关于android – 保护VpnService中的套接字、Delphi 2009,Indy 10,TIdTCPServer.OnExecute,如何获取InputBuffer中的所有字节、Delphi 7 中使用Indy创建独立的 Web Services/SOAP 服务器(一)、Delphi 7 中使用Indy创建独立的 Web Services/SOAP 服务器(三)的相关知识,请在本站寻找。
本文标签: