Delphi:TTcpServer,读取时连接重置

发布于 2024-08-09 02:21:20 字数 1069 浏览 3 评论 0原文

我正在尝试为 delphi 实现 Fitnesse Slim 服务器,但遇到一些问题的沟通。

Fitnesse 将启动我的进程,并给我一个端口号作为命令行参数。

然后我应该在给定的端口号创建一个套接字,Fitnesse 将连接到该端口。

我使用 TTcpServer 来完成这项工作:

TcpServer1.LocalPort := ParamStr(ParamCount);
TcpServer1.Active := true;

在 OnAccepted( ) 事件中,我发送要使用的协议版本,如规范中指定的那样。

procedure TForm1.TcpServer1Accept(Sender: TObject;
  ClientSocket: TCustomIpClient);
var
  s: ansistring;
begin
  ClientSocket.Sendln('Slim -- V0.0', #10);
  setLength(s, 6);
  ClientSocket.ReceiveBuf(s, 6);
end;

当我调用 ReceiveBuf( ) 时,进程结束,fitnesse 抛出异常:

java.net.SocketException: Connection reset

我使用了 oSpy 查看发送和接收的内容。它表明,在我的代码发送协议版本后,fitnesse 发回一条消息,并且当我尝试接收此消息时,连接被重置。

有谁知道这可能是什么原因? 我做错了什么吗?

顺便说一句,当我使用fitnesse附带的java slim服务器时,一切正常。然后,oSpy 显示相同的通信,直到第一次读取为止。虽然我的阅读尝试失败了,但这篇文章按预期工作。

I'm trying to implement a Fitnesse Slim server for delphi, but have some problems with the communication.

Fitnesse will start my process, and give me a portnumber as a commandline argument.

Then I'm supposed to create a socket at the given portnumber, and Fitnesse will connect to that port.

I'm using a TTcpServer for the job:

TcpServer1.LocalPort := ParamStr(ParamCount);
TcpServer1.Active := true;

In the OnAccepted( )-event, I send the protocol version to use, as specified in the spec.

procedure TForm1.TcpServer1Accept(Sender: TObject;
  ClientSocket: TCustomIpClient);
var
  s: ansistring;
begin
  ClientSocket.Sendln('Slim -- V0.0', #10);
  setLength(s, 6);
  ClientSocket.ReceiveBuf(s, 6);
end;

When I call ReceiveBuf( ), the process ends, and fitnesse throws an exception:

java.net.SocketException: Connection reset

I have used oSpy to see what get sent and received. It shows that after my code sends the protocol version, fitnesse sends a message back, and that the connection is reset when I try to receive this message.

Does anybody know what the reason for this can be?
Am I doing something completely wrong?

Btw, everything works ok when I use the java slim server that comes with fitnesse. oSpy then shows the same communication, up to the first read. While my attempt to read fails, this one works as expected.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

给我一枪 2024-08-16 02:21:20

查看此网站的 delphi Fit 服务器 + 源代码

have a look at this web site for a delphi Fit server + source code

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文