Re: How to PostThreadMessages?



Just curious, can the machine terminate a connection WHILE transferring a
file??

So, you post a request for a file, a machine sends a response that contains
that file, and in the midst of sending decides that it'd be cool to just
drop the connection?

Or does it happen that you post your request and the machine does not
respond immediately? Say, in a coupla minutes, and meanwhile it wants the
connection to stay alive (hence "keep-alive" messages)?

"jp2code" <poojo.com/mail> wrote in message
news:uPvh6h3pHHA.4872@xxxxxxxxxxxxxxxxxxxxxxx
All good info!

Let me give everyone a little background:

We have machines with serial ports running and collecting record data.

This app will interface with a machine to download log files or
occasionally upload a new config file.

To get a log file, we post a request and wait for the machine to transmit
the reply with the file.

A little catch is that we have to send a short keep-alive signal every X
milliseconds, or the machine will terminate the connection.

This thread will send the keep-alive signals until the User disconnects
the machine.

We can not use asynchronous data transfer, so Overlapped Results is out. I
check that the port is clear, block the port, read from the port, then
unblock. Same for writing to the port.

There is no user interface, but I do need to send occasional messages to
the thread.

Originally, I had been running a thread using CreateThread, but it looks
like that is not allowing the entire class to thread nicely.

I don't really understand what Mr. Newcomer said, "You have to create a UI
thread to handle this sort of thing, but it can't be doing anything else
interesting for any long period of time or the thread messages won't be
dequeued."

Every X milliseconds, the thread send a keep-alive signal, then scans the
serial port for messages.

To answer Mr. Geodakov, my ZSerialThread class is derived from CWinThread,
and I have declared my thread to start as follows:

(Global)
ZSerialThread* pSerial;
(Later in code)
pSerial = (ZSerialThread*)AfxBeginThread(RUNTIME_CLASS(ZSerialThread));

Is this correct? Is it ok for my thread "handle" to be global? This way, I
can post thread messages from within the thread or from the main dialog
application (the user interface).

Mr. McPhillips, your post was the clearest to understand, except for the
part where you said, "your thread's InitInstance will execute, and then
the thread goes to sleep until it receives a message." Is there any
specific message I need to give my thread to begin execution? I would be
happy if the thread started running my scanning loop as soon as it were
created.

I have also created my Thread Message loop as follows:
//---------------------------------------------------------------------------
void ZSerialThread::OnSerialMessage(WPARAM wParam, LPARAM lParam)
{
switch (wParam)
{
case NEWCOM: // change COM Port
if (lParam != NULL)
ChangeCommPort((LPTSTR)lParam);
break;
case STARTIT: // Start the Loop!
ScanSerialPort();
break;
case TH_DON: // End the thread
PostQuitMessage(0);
g_LoopSerial = FALSE;
break;
}
}

Any comments, good or bad?



.



Relevant Pages

  • Re: HTTPhandlers
    ... When I try to have the> TcpListener listen on port 80 I get this error stating that port is already> in use or something. ... > Some request get redirected and others are left to any other process that> wants them like IIS or some other web server. ... >> The link you provided does not explain how to hold a connection open over HTTP - unless the answers to the query do, but this requires a subscription which I'm not prepared to pay. ... Is there any other way for me to be able to see the technique that keeps an HTTP based connection active over a long period? ...
    (microsoft.public.dotnet.framework)
  • RE: NT Compromise
    ... TCP port 6667 and 6668 are used for IRC. ... to this it seems that your server might have connection to one of IRC ... Subject: NT Compromise ... has timed out a request to STEELSRV. ...
    (Incidents)
  • Re: HTTPhandlers
    ... One thing you can probably do is to have a different port based server to ... which you make the request to do the connection with the user and maintain ... > It comes down to that I have written this very efficient DHTML chat server> that maintains an active connection with the browser. ... >> information about an individual HTTP request. ...
    (microsoft.public.dotnet.framework)
  • Re: Socket Pools?
    ... Get the users to use a UDP Port to request a Connection, ... > I want users of this class to be able to request a socket and if one isn't ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Correction
    ... Normally to physically disconnect is just a matter of reaching for the ... >> I have an ADSL connection which polls my computer from time to time, ... > disallow each and every port with Windows Firewall? ...
    (microsoft.public.windowsxp.messenger)