0

I'm writing a server that send an XDR struct over a socket. Using Wireshark I see that my client correctly send an XDR message to the server BUT I don't see any data go from the server to the client. But the code seems to be correct as it is the same used for the client. I have see that the problem is xdr_Response. Is there any mistake on it? Thanks to all

XDR xdrs_w;
Response y;

stream_socket_w = fdopen(s, "w");
xdrstdio_create(&xdrs_w, stream_socket_w, XDR_ENCODE);

y.error = 0; 
y.result = 5.7;

xdr_Response(&xdrs_w, &y);
fflush(stream_socket_w);

with:

struct Response {
    bool_t error;
    float result;
};
typedef struct Response Response;
user2467899
  • 583
  • 2
  • 6
  • 19

1 Answers1

2

I'm not very expert of XDR, but I found a way that worked to receive data from XDR with a socket connection (on TCP). First you have to do recv to receive the data from your client, then call xdrmem_create(), that need the XDR structure that you'll use to the reading, a buffer (a string), the return value of recv(), and you have to use XDR_DECODE because you're writing from XDR that's codified.

You have to write something like this:

l = recv(socket, buffer, BUFFERDIM, 0);
xdrmem_create(&xdrs_w, buff, l, XDR_DECODE );
if(!xdr_Response(&xdrs_w, &y) {
fprintf(stdout, "Error XDR\n");
}
fprintf(stdout, "Received: %f", y.result);

and y should be filled in. Note that buffer is different from buff. I prefer to do this instead of use fd_open, you've only to create the xdr and call xdr_Response.

Fopa Léon Constantin
  • 11,863
  • 8
  • 48
  • 82
A. Wolf
  • 1,309
  • 17
  • 39