Delphi: TTcpServer, connection reset when reading

2019-04-16 22:30发布

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.

1条回答
姐就是有狂的资本
2楼-- · 2019-04-16 23:09

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

查看更多
登录 后发表回答