Home Forums Support "Timeout occurred after 1000ms waiting for response packet of type 'Data Table'"

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #937
    Anonymous
    Inactive

    Hi,
    I’m trying to ask for a DataTable and send it back to the client but I get this error message:
    “Timeout occurred after 1000ms waiting for response packet of type ‘Data Table'”

    This is the client code:

    //Create a connectionInfo object that specifies the target server
                    ConnectionInfo connectionInfo = new ConnectionInfo("127.0.0.1", 10000);
    
                    //Get a connection with the specified connectionInfo
                    TCPConnection serverConnection = TCPConnection.GetConnection(connectionInfo);
    
                    //Or we could also create the connection using UDP?
                    //UDPConnection serverConnection = UDPConnection.GetConnection(connectionInfo, UDPOptions.None);
    
                    //Send a packet of type RequestCustomObject and wait synchronously until
                    //a. The server returns the requested CustomObjectReply packet continaing a CustomObject
                    //b. We have waited for atleast 1000ms at which point we timeout and throw an ExpectedReturnTimeoutException
                    //Note: There are 6 overrides for SendReceiveObject that should provide the whole range of required features
                    //The override we are using here just requests some data without providing an object to send
                    DataTable tables = serverConnection.SendReceiveObject<DataTable>("RequestCustomObject", "DataTable", 1000);

    This is the server code:

                InitializeComponent();
    
                //Append a packet handler that will get executed when the server receives a "RequestCustomObject" packetType.
                //Note: The expected incoming object type here is irrelevant because the client is not providing an object
                //If the client does not provide an object when sending the incoming object is set to GetDefault(Type).
                NetworkComms.AppendGlobalIncomingPacketHandler<DataTable>("RequestCustomObject", (packetHeader, connection, input) =>
                {
    
                    listBoxLog.Items.Add("RetrieveAllTables started");
                    //For this short example we just reply with a new CustomObject
                    DataTable allTables = sql.RetrieveAllTables();
                    listBoxLog.Items.Add("Tables retrieved from DB");
    
                    //When this is received by the client it will complete the synchronous request
                    connection.SendObject("RequestCustomObject", allTables);
                    listBoxLog.Items.Add("Tables sent");
                });
                TCPConnection.StartListening(true);

    It stops at connection.SendObject(“RequestCustomObject”, allTables);

    Maybe it’s something easy but I can’t figure it out. Thanks in advance for helping me solve this!

    Best regards,
    Tomas

    #938
    Anonymous
    Inactive

    Ok, so if I’m right it is not possible to send a DataTable like this, I need to serialize it first.

    Here is some info if I’m right:
    http://stackoverflow.com/questions/16314958/pass-data-table-from-server-to-client-using-tcp-c-sharp

    http://stackoverflow.com/questions/2244655/how-to-serialize-a-datatable-to-a-string

    #939
    Anonymous
    Inactive

    If I run this code it works perfectly:

                NetworkComms.AppendGlobalIncomingPacketHandler<string>("RequestString", (packetHeader, connection, input) =>
                {
                    //For this short example we just reply with a new CustomObject
    
                    string myCustomObject = "Hejsan";
                    myCustomObject += "2";
    
                    /*DataTable t = sql.RetrieveAllTables();
                    string temp = "";
                    t.WriteXml(temp);*/
    
                    //listBoxLog.Items.Add(myCustomObject);
    
                    
                    
                    //When this is received by the client it will complete the synchronous request
                    connection.SendObject("StringReply", myCustomObject);
                });

    But if I add some more code, which has nothing to do with the object being sent it returns the Timeout error:

                NetworkComms.AppendGlobalIncomingPacketHandler<string>("RequestString", (packetHeader, connection, input) =>
                {
                    //For this short example we just reply with a new CustomObject
    
                    string myCustomObject = "Hejsan";
                    myCustomObject += "2";
    
                    DataTable t = sql.RetrieveAllTables();
                    string temp = "";
                    t.WriteXml(temp);
    
                    //listBoxLog.Items.Add(myCustomObject);
    
                    
                    
                    //When this is received by the client it will complete the synchronous request
                    connection.SendObject("StringReply", myCustomObject);
                });

    Can someone please help me explain why?

    Thanks in advance!

    #940
    Anonymous
    Inactive

    Heya tomas,

    Welcome to out forums and thank-you for your interest in our library. We’ll certainly help as much as we can.

    1) Timeout occurred after 1000ms waiting for response packet of type 'Data Table' – This exception is correctly thrown by the client if it does not receive the expected reply after the provided timeout.

    2) If an exception occurs within a packethandler and you do not catch it yourself NetworkComms.Net should save out an error file with some useful information. This should be in the application execution directory. You mention in your second example that adding the following code prevents the object being sent:

    DataTable t = sql.RetrieveAllTables();
    string temp = ""
    t.WriteXml(temp);

    My guess is that code snippet is throwing some sort of exception which prevents the SendObject method being called.

    3) NetworkComms.Net will attempt to automatically serialise/deserialise the object being sent, in this case a DataTable. If it is unable to serialise/deserialise an exception will be thrown or log file will be created by the client or server depending on where the problem occurred, see point 1 above. If DataTableis not successfully serialised/deserialised your best solution is to create a suitable wrapper object. We wrote a tutorial regarding this issue which uses an Imageobject as an example, https://networkcomms.net/custom-objects/.

    Hopefully the above solves your issues, if not please feel free to post back.

    Regards,
    Marc

    #942
    Anonymous
    Inactive

    Hi, thanks for your reply. I think the WriteXml was throwing an exception which I didn’t see.

    I solved it like this:

                NetworkComms.AppendGlobalIncomingPacketHandler<string>("RequestString", (packetHeader, connection, input) =>
                {
                    //For this short example we just reply with a new CustomObject
                    DataTable t = sql.RetrieveAllTables();
                    t.TableName = "Tables";
                    StringWriter writer = new StringWriter();
    
                    //notice that we're ignoring the schema so we get clean XML back
                    //you can change the write mode as needed to get your result
                    t.WriteXml(writer, XmlWriteMode.IgnoreSchema, false);
    
                    string myCustomObject = writer.ToString();
    
                    //listBoxLog.Items.Add(myCustomObject);
    
                    
                    
                    //When this is received by the client it will complete the synchronous request
                    connection.SendObject("StringReply", myCustomObject);
                });

    And on the other side I just read the XML data.

    Another question which I am struggeling with right now is how do I send a multidimensional array (string[,])?

    Do I need to use that wrapper which you linked to?

    Best regards,
    Tomas

    #943
    Anonymous
    Inactive

    Yea, 1D arrays (and I believe jagged arrays providing they are in a wrapper class) are not a problem. Multidimensional arrays however can’t be serialised, you need to break them down using the link I gave. Converting a multidimensional to a jagged array and back again is relatively straight forward. Before you do that just ensure jagged arrays in a wrapper class do indeed work.

    Marc

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.