Home › Forums › Support › "Timeout occurred after 1000ms waiting for response packet of type 'Data Table'"
- This topic has 5 replies, 2 voices, and was last updated 11 years, 5 months ago by Anonymous.
-
AuthorPosts
-
June 25, 2013 at 04:05 #937AnonymousInactive
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,
TomasJune 25, 2013 at 05:26 #938AnonymousInactiveOk, 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-sharphttp://stackoverflow.com/questions/2244655/how-to-serialize-a-datatable-to-a-string
June 25, 2013 at 06:52 #939AnonymousInactiveIf 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!
June 25, 2013 at 10:38 #940AnonymousInactiveHeya 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. IfDataTable
is not successfully serialised/deserialised your best solution is to create a suitable wrapper object. We wrote a tutorial regarding this issue which uses anImage
object as an example, https://networkcomms.net/custom-objects/.Hopefully the above solves your issues, if not please feel free to post back.
Regards,
MarcJune 25, 2013 at 11:20 #942AnonymousInactiveHi, 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,
TomasJune 25, 2013 at 11:27 #943AnonymousInactiveYea, 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
-
AuthorPosts
- You must be logged in to reply to this topic.