Thread overview
How to recursively accept data from Python server ?
Jun 25, 2021
Utk
Jun 25, 2021
mw
Jun 25, 2021
jfondren
Jun 25, 2021
Utk
Jun 25, 2021
Utk
June 25, 2021

Hello!
I'm trying to establish a connection between a python server and a d client. The data is been transferred properly only once and then the d client doesn't wait for any further data and returns an error Socket.ERROR and exists and doesn't wait for further incoming data from the Python server. From Python, the data is been sent whenever the user sends a request but instead of waiting for incoming requests the D client just accepts the data 1st time and then throws an error and exits.
The code snippet is as below:

bool get_req_from_socket(Socket socket) {

    ubyte[] rawTrHeader;
    ubyte[] buffer;

    writeln("Waiting for data from socket");
    while (rawTrHeader.length < 16) {
      import std.string: format;

      buffer.length = 16 - rawTrHeader.length;
      auto ret = socket.receive(buffer);
      uvm_info("SOCKET", format("Received %d bytes from socket", ret),
	       UVM_DEBUG);
      if (ret == Socket.ERROR)
	uvm_fatal("SOCKET", "Error receiving data from socket");
      if (ret == 0)
	uvm_fatal("SOCKET", "Got insufficient bytes for TrHeader");
      // now slice the buffer to get the part...
      rawTrHeader ~= buffer[0 .. ret];
    }
    ...
    ...
  }

This is the function (infinitely called while it returns true) that accepts the data and returns true or false depending on if data is received or not respectively.
The error I'm receiving is:

Waiting for data from socket
UVM_INFO ../testbench/apb.d(375) @ 130000: reporter@@apb_seq [SOCKET] Received -1 bytes from socket
UVM_FATAL ../testbench/apb.d(378) @ 130000: reporter@@apb_seq [SOCKET] Error receiving data from socket

Please help me to resolve this issue.

June 25, 2021

Not sure if you want build interprocess communication utility all by yourself, I'm currently using

https://code.dlang.org/packages/apache-thrift

and there is also

https://code.dlang.org/packages/symmetry_thrift_d

BTW grpc is not quiet working

https://code.dlang.org/packages/grpc

June 25, 2021

On Friday, 25 June 2021 at 02:55:50 UTC, Utk wrote:

>

Please help me to resolve this issue.

Try stracing your program to see exactly what it's doing
with the socket, and try std.socket's lastSocketError

June 25, 2021

On Friday, 25 June 2021 at 03:27:24 UTC, jfondren wrote:

>

On Friday, 25 June 2021 at 02:55:50 UTC, Utk wrote:

>

Please help me to resolve this issue.

Try stracing your program to see exactly what it's doing
with the socket, and try std.socket's lastSocketError

I tried using lastSocketError(), it gave an error saying Connection reset by peer. I'm confused about how the connection is getting reset.

Here's the complete code: https://github.com/utkarshb1/Interactive-Register-Debugging/blob/7919612396cf893bb5e9b936c2d8a44663ac6733/apb_slave/testbench/apb.d#L289
I'm receiving that error at line 362.

The code should continuously wait for the data from python and once received it should do the computation defined in the code and then again wait for the data until EXIT signal is sent from python.

June 25, 2021

On Friday, 25 June 2021 at 05:46:54 UTC, Utk wrote:

>

On Friday, 25 June 2021 at 03:27:24 UTC, jfondren wrote:

>

On Friday, 25 June 2021 at 02:55:50 UTC, Utk wrote:

>

Please help me to resolve this issue.

Try stracing your program to see exactly what it's doing
with the socket, and try std.socket's lastSocketError

I tried using lastSocketError(), it gave an error saying Connection reset by peer. I'm confused about how the connection is getting reset.

Figured it out! The error was on the python side as I was not receiving the data from d which was locally buffered.