UNIX Socket FAQ

A forum for questions and answers about network programming on Linux and all other Unix-like systems

You are not logged in.

  • Index
  • » C++
  • » Is this the best way to do this?

#1 2009-01-22 06:02 PM

arm
Guest

Re: Is this the best way to do this?

Good morning and thanks in advance for your time and help.

We're trying to develop an application that will let a handheld scanner (HH) to connect to a Windows server. Every now and then, the device gets a time out trying to get a response from the server. The HH has a time limit of 7 seconds.

I'm going to try to explain what the process is:

1. User presses the enter key to send the request for log in. This connection process goes HH <-> Access point <-> App Server
2. Once the server received the request, it tries to get the device Id and assigns it a session.
3. At the same time, the app builds the screen and sends it back to the HH.
4. HH displays screen.

We noticed that the problem seems to be in number 2. On the log file, we see the device id and right after that, takes an average of 10 secs to build the screen. Our guess is that the problem is here.

Thanks again for your help.


This is the source code:

using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using System.Runtime.InteropServices;
using System.Threading;
using System.Diagnostics;
using System.IO;

...
        void RFOPEN(ref int iPTCNo, ref int iPTCType);

...
        public void RFOPEN(ref int iPTCNo, ref int iPTCType)
        {
            //LogForDebugPurpose("RFOPEN");
            SocketClient sockClient = SocketClient.GetClientInstance();
            sockClient.SendDataToDevice("INFO", "", "PTC ID");
            while (WhetherToLoopAgain) //WhetherToLoopAgain = true
            {
                if (SocketClient.DataRecieved != "")
                { WhetherToLoopAgain = false; }

                Thread.Sleep(100);
            }
            string st = SocketClient.DataRecieved;
            WhetherToLoopAgain = true;
            RFCommands.LogForDebugPurpose("DIv id:" + st + " RFOPEN");
            SocketClient.DataRecieved = "";
            iPTCNo = Int32.Parse(st);

            //Need to send PTC no and PTC Type to Process Manager
        }

#2 2009-01-23 01:16 AM

i3839
Oddministrator
From: Amsterdam
Registered: 2003-06-07
Posts: 2,234

Re: Is this the best way to do this?

(Moved this to the C++ forum instead of the bugs one, which is for forum bugs.)

Try removing that Sleep(100), in general you never want to do anything like
that. If you need it to "work" then you probably have a bug somewhere.

That WhetherToLoopAgain = true; looks dodgy as well, you just set it to
false a moment before. So either you shouldn't set it to false there, or you
shouldn't set it to true here. Or I'm missing something.

If that WhetherToLoopAgain is meant to handle short reads, it's not doing
it correctly, as new data isn't appended to st but replaces it. That st part
should probably be out of the WhetherToLoopAgain loop and do
st += SocketClient.DataRecieved.

But 10 seconds to build the screen seems awfully lot, is that after receiving a
scanned image and you're sending it back or something?! It's a bit unclear
what exactly happens here.

Offline

  • Index
  • » C++
  • » Is this the best way to do this?

Board footer

Powered by FluxBB