Delphi:TTcpServer,读取时重新连接 [英] Delphi: TTcpServer, connection reset when reading

查看:133
本文介绍了Delphi:TTcpServer,读取时重新连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为delphi实施一个 Fitnesse Slim server ,但是一些通信问题。

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

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

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

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

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

我正在使用TTcpServer作为工作:

I'm using a TTcpServer for the job:

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

在OnAccepted()-event中,我发送协议版本使用,如规范中所指定。

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;

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

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

java.net.SocketException: Connection reset

我已使用 oSpy 查看发送和接收的内容。它显示,在我的代码发送协议版本后,fitnesse发送一条消息,当我尝试收到此消息时,该连接被重置。

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,一切都可以正常,当我使用来自fitnesse的java超薄服务器。 oSpy然后显示相同的通信,直到第一次读取。当我尝试读取失败时,这个按预期工作。

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.

推荐答案

看看这个网站的一个 delphi适合服务器 +源代码

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

这篇关于Delphi:TTcpServer,读取时重新连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆