login about faq

I am using ActiveX Socket with FoxPro and do not trigger events when receiving data in the buffer on an active connection.

asked Dec 20 '16 at 19:19

chilkat's gravatar image

chilkat ♦♦
12.8k317367485


This answer is general and applies to any programming language on any operating system.

I get this question from time to time, and the short answer is that your application needs to either poll the socket for incoming data, or it must wait on the socket for data to arrive. Of course, if you have the ability to start your own background thread, you could read the socket in the background and notify your foreground thread (by some application-defined means) when data is available.

You could also make a call to one of the asynchronous socket reading/waiting methods, such as ReceiveBytesAsync, SelectForReadingAsync, etc., in which case the background task would wait on the socket. However, the TaskCompleted callback is only possible in some programming languages (such as C++). For the ActiveX, it's generally not possible because the TaskCompleted callback would be in the background thread, and it would have to cross a thread boundary to get to the application code running in the foreground thread.

I sense that many people have this notion that somehow, when data arrives on a socket, that the operating system can magically notify a program, and that some "event" can fire. This isn't the case. Not with a high-level programming language. Maybe it's possible with code closer to the "metal" such as C/C++, but even that's not usually a good idea. (Google "SIGIO handler" to see what I mean..)

link

answered Dec 20 '16 at 19:54

chilkat's gravatar image

chilkat ♦♦
12.8k317367485

Ah the beauty of the UNIX OS!

link

answered Dec 23 '16 at 10:09

cdlvj130's gravatar image

cdlvj130
12691118

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or __italic__
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×81
×12
×2

Asked: Dec 20 '16 at 19:19

Seen: 468 times

Last updated: Dec 23 '16 at 10:09

powered by OSQA