Discussion:
MSWinsock.ocx - server: handle more than a single connection & share events
(too old to reply)
R.Wieser
2017-04-04 16:37:40 UTC
Permalink
Hello all,

After having figured out my previous problem (not getting events) I almost
directly bumped into another one: Imagine a simple HTTP server, which
should be able to handle several requests at a time. Almost directly a few
problems pop-up. Googeling for

1) How do I get a single listening socket to "spawn" multiple data
sockets -- the standard method of closing the listening socket down and than
accepting the new connection on the now-free socket would, AFAICS, cause
other waiting connection-requests to be dropped. Which is double-plus
non-good.

2) How do I get to share the events for the different data-sockets ? --
Although MSDN* tells me that the MSWinsock control should be able to work
as/in a "control array" and the connectionRequest event supposedly has an
"index" argument, looking at the typelib exposed by the MSWinsck.ocx
control** I have here I can't discover the first (no index property) nor the
second (the connectionRequest event shows it has only got a single argument
(supposedly the connectionID) )

* https://msdn.microsoft.com/en-us/library/aa733709(v=vs.60).aspx

** v6.0 SP5.

TL;DR: Does someone have an example handy which shows the basics of a
multi-connection MSWinsock server for a Win98se environment ? I could
surely use one -- if only to figure out how the different parts play
together.

Regards,
Rudy Wieser
Mayayana
2017-04-04 17:34:18 UTC
Permalink
"R.Wieser" <***@not.available> wrote

|
| TL;DR: Does someone have an example handy which shows the basics of a
| multi-connection MSWinsock server for a Win98se environment ? I could
| surely use one -- if only to figure out how the different parts play
| together.

I can't imagine what you're planning in trying to set
up a multiple port server through a VBScript. In any case,
that's a VB6 control. The indexing is in the VB6 environment.
In other words, plop 3 of them on a VB6 form with the same
name and VB will make them an array. VBScript is not
going to do that. It's not part of the control functionality.

I use VB6 a lot but have never used the Winsock
control. I just use Windows sockets directly. I have a
free http ActiveX EXE, but I'm not sure it will do what
you want:

http://www.jsware.net/jsware/compfiles.php5#jshttp

It's not a winsock wrapper. It handles the dirty work
to do specific things, like downloading files.
R.Wieser
2017-04-04 20:49:17 UTC
Permalink
Mayayana,

The indexing is in the VB6 environment.
Post by Mayayana
In other words, plop 3 of them on a VB6 form with the
same name and VB will make them an array
Understood. That makes everything even harder, as in plain VBS/wscript
none of the WinSock events than carry any indication to which object fired
them ...

And odd: Why does the ConnectionRequest event deliver a "requestID" which
than needs to be used with the accept method. I mean, there is-and-can-be
only a single socket for any existing WinSock object, so why than that, as
far as I can tell, rather superfluous ID ?
Post by Mayayana
I have a free http ActiveX EXE, but I'm not sure it will do
Thanks, but if I can't get that MSWinSock object to do what I want I might
have some fun in writing one myself. :-)

Regards,
Rudy Wieser
Post by Mayayana
|
| TL;DR: Does someone have an example handy which shows the basics of a
| multi-connection MSWinsock server for a Win98se environment ? I could
| surely use one -- if only to figure out how the different parts play
| together.
I can't imagine what you're planning in trying to set
up a multiple port server through a VBScript. In any case,
that's a VB6 control. The indexing is in the VB6 environment.
In other words, plop 3 of them on a VB6 form with the same
name and VB will make them an array. VBScript is not
going to do that. It's not part of the control functionality.
I use VB6 a lot but have never used the Winsock
control. I just use Windows sockets directly. I have a
free http ActiveX EXE, but I'm not sure it will do what
http://www.jsware.net/jsware/compfiles.php5#jshttp
It's not a winsock wrapper. It handles the dirty work
to do specific things, like downloading files.
Mayayana
2017-04-04 21:00:32 UTC
Permalink
"R.Wieser" <***@not.available> wrote

| > I have a free http ActiveX EXE, but I'm not sure it will do
| > what you want:
|
| Thanks, but if I can't get that MSWinSock object to do what I want I might
| have some fun in writing one myself. :-)
|
In that case you could internalize indexing
and anything else you like. I find the problem
of stasis in VBS very awkward. One has to keep
doing *something*. I chose to get around that
by having a Busy property in my AxEXE. So
I don't need anything like Sleep. I just do something
like

Obj.DownloadFile URL
While Obj.Busy = True
Wend

The control then sends the event and sets Busy
false when the download is ready.
R.Wieser
2017-04-05 07:52:19 UTC
Permalink
Mayayana,
Post by Mayayana
In that case you could internalize indexing
and anything else you like.
In that case I would not even use an index. I would than not have the
object return a socket (like MSWinSck does), but just behave as an
entry-point for whatever I further want to do, exposing methods like
"connect" and "listen" commands which return "socket" objects. :-) (but
although the "sockets" could be put into a user-defined array or dictionary
object and handled that way, I would most likely include an enumeration
method for them)
Post by Mayayana
I find the problem of stasis in VBS very awkward. One has to keep
doing *something*.
True. But thats a drawback/shortcoming of both W- and CScript.exe. When
you put a scripting engine into a program of your own you can hold-off the
actual closing of the engine itself for as long as you want, allowing you to
still do call-backs into the script.

But yes, I've also been thinking about the same. For example, I've created
a small "logging window" OCX, which I use to "print" to when I run a script
in GUI mode (using WScript), as I got fed up with either not knowing what
was going on, or have a steady stream of "must click to dismiss" msgbox
alerts. I would really like to be able to have, in the end, the script wait
for the "logging window" to be closed (by the user) before actually
terminating.

And as stuff goes, I just realized that possiby wanting to keep "events"
running makes that even harder to accomplish. :-\ :-)
Post by Mayayana
I chose to get around that by having a Busy property in
my AxEXE. So I don't need anything like Sleep.
And that tight loop still allows events to be handled ? Remarkable.

My own attempt to create an all-script "sleep" is the below. Alas, it
didn't work (in regard to events).

- - - - - - - - - - - - - - - -
sub WaitSome(seconds)
dim dummy
for i=0 to seconds
dummy=second(now)
while dummy=second(now)
wend
next
end sub
- - - - - - - - - - - - - - - -

Mind you, the delay works works well enough in itself.

Regards
Rudy Wieser


-- Origional message
Post by Mayayana
| > I have a free http ActiveX EXE, but I'm not sure it will do
|
| Thanks, but if I can't get that MSWinSock object to do what I want I might
| have some fun in writing one myself. :-)
|
In that case you could internalize indexing
and anything else you like. I find the problem
of stasis in VBS very awkward. One has to keep
doing *something*. I chose to get around that
by having a Busy property in my AxEXE. So
I don't need anything like Sleep. I just do something
like
Obj.DownloadFile URL
While Obj.Busy = True
Wend
The control then sends the event and sets Busy
false when the download is ready.
Mayayana
2017-04-05 19:32:05 UTC
Permalink
"R.Wieser" <***@not.available> wrote

| > I chose to get around that by having a Busy property in
| > my AxEXE. So I don't need anything like Sleep.
|
| And that tight loop still allows events to be handled ?
|
Yes. Because it's tight.

While Obj.Busy = True
Wend

That leaves it checking constantly. When my component
makes a file request via winsock it makes it through a
winsock userControl. If that request is OK it sets Busy = True.
The winsock UC then sends an event when the file is
finished downloaded. With that event the component
raises the event for the scriot, OnDownloadFinish, and
then sets Busy = False.

It gets complicated, but doing things in that order
seems to work.
R.Wieser
2017-04-06 08:15:40 UTC
Permalink
Mayayana,
When my component makes a file request via winsock it
makes it through a winsock userControl. If that request is
OK it sets Busy = True.
Ah, thataway. I was stuck thinking about a generic "just wait" loop, and
just didn't recognise/realize that it was a "do you need to do something ?"
check. :-\

Yep, that works. And as it doesn't even actually sleep you can even stack
a number of those checks for multiple incarnations of objects using the same
method.

One drawback though: that method will most likely keep your processor
running at 100% ...

And I was thinking of why you could not simply use a blocking call like
"select", but realized that your method allows for multiple objects/sockets
to be active-and-checked at the same time.

Regards,
Rudy wieser.
| > I chose to get around that by having a Busy property in
| > my AxEXE. So I don't need anything like Sleep.
|
| And that tight loop still allows events to be handled ?
|
Yes. Because it's tight.
While Obj.Busy = True
Wend
That leaves it checking constantly. When my component
makes a file request via winsock it makes it through a
winsock userControl. If that request is OK it sets Busy = True.
The winsock UC then sends an event when the file is
finished downloaded. With that event the component
raises the event for the scriot, OnDownloadFinish, and
then sets Busy = False.
It gets complicated, but doing things in that order
seems to work.
Mayayana
2017-04-06 13:42:34 UTC
Permalink
"R.Wieser" <***@not.available> wrote

| One drawback though: that method will most likely keep your processor
| running at 100% ...
|

Interesting point. That seems true, but it doesn't
seem to work that way. All compiled software is
basically running a loop to keep going. And there's
no freezeup.

I don't know how it works technically.

I'd guess that maybe the process just forfeits its
CPU timeslice each time it comes around, so that
no CPU load is recorded. That would explain how
20 processes can be loaded but not using resources.
They're all prepared to respond in the next microsecond
that they're offered a timeslice, but they pass on the
offer. Like a bottle of wine being passed endlessly
around at an AA meeting. The wine is never dissipated
but is always available in short order if anyone decides
to drink.
R.Wieser
2017-04-06 15:47:34 UTC
Permalink
Mayayana,
Post by Mayayana
Interesting point. That seems true, but it doesn't
seem to work that way.
...
Post by Mayayana
I'd guess that maybe the process just forfeits its
CPU timeslice each time it comes around,
:-) I did not think about other programs/tasks. But yes, than the
time-slice manager will make sure that other programs get some time to run
too.

And by the way, this afternoon I tried to take a peek in wscripts "sleep"
method. It seems to do one-second sleeps and calls other stuff in between.
I imagine that it could be doing VBScripts version of short sleeps and "do
events" calls.
Post by Mayayana
Like a bottle of wine being passed endlessly
around at an AA meeting. The wine is never dissipated
but is always available in short order if anyone decides
to drink.
Can I have one of those bottles please ? :-)

Regards,
Rudy Wieser
Post by Mayayana
| One drawback though: that method will most likely keep your processor
| running at 100% ...
Interesting point. That seems true, but it doesn't
seem to work that way. All compiled software is
basically running a loop to keep going. And there's
no freezeup.
I don't know how it works technically.
I'd guess that maybe the process just forfeits its
CPU timeslice each time it comes around, so that
no CPU load is recorded. That would explain how
20 processes can be loaded but not using resources.
They're all prepared to respond in the next microsecond
that they're offered a timeslice, but they pass on the
offer. Like a bottle of wine being passed endlessly
around at an AA meeting. The wine is never dissipated
but is always available in short order if anyone decides
to drink.
JJ
2017-04-04 17:42:20 UTC
Permalink
Post by R.Wieser
Hello all,
After having figured out my previous problem (not getting events) I almost
directly bumped into another one: Imagine a simple HTTP server, which
should be able to handle several requests at a time. Almost directly a few
problems pop-up. Googeling for
1) How do I get a single listening socket to "spawn" multiple data
sockets -- the standard method of closing the listening socket down and than
accepting the new connection on the now-free socket would, AFAICS, cause
other waiting connection-requests to be dropped. Which is double-plus
non-good.
Accept the connection, but do further processing on it at later time using a
timer. The important thing is to let the VBScript enters the idle state so
that any pending connection events can be passed to the VBScript by the
Winsock OCX.
Post by R.Wieser
2) How do I get to share the events for the different data-sockets ? --
Although MSDN* tells me that the MSWinsock control should be able to work
as/in a "control array" and the connectionRequest event supposedly has an
"index" argument, looking at the typelib exposed by the MSWinsck.ocx
control** I have here I can't discover the first (no index property) nor the
second (the connectionRequest event shows it has only got a single argument
(supposedly the connectionID) )
* https://msdn.microsoft.com/en-us/library/aa733709(v=vs.60).aspx
** v6.0 SP5.
TL;DR: Does someone have an example handy which shows the basics of a
multi-connection MSWinsock server for a Win98se environment ? I could
surely use one -- if only to figure out how the different parts play
together.
Type Library is only for a reference for applications which don't know what
members are available in a COM interface, or need to know what interface and
their members are available. It's not really a requirement. Any COM/ActiveX
can be fully functional even if it doesn't have embedded or external Type
Library. COM/ActiveX modules are the one that validate whether an interface
member name is available or not, not the application that use them.

Just follow example code in that page and treat the control as if it's an
array of objects. See below page if you're still confused.

<http://www.devx.com/tips/Tip/5488>
R.Wieser
2017-04-04 21:03:58 UTC
Permalink
JJ,
Post by JJ
The important thing is to let the VBScript enters the idle state so
that any pending connection events can be passed to the VBScript
by the Winsock OCX.
That won't work, as I have no control over when a connection request comes
in. Furthermore, the response the vbscript server returns might provoke
another request ...

And as Mayayana just made clear to me (no "control array" in vbscript), I
*can't* accept more than a single connection, as I've got only a single
object (read: socket) available to run the "accept" method against ... (or
that "requestID" must be usable by other incarnations ofthe same object, but
I doubt that).
Post by JJ
Type Library is ... not really a requirement.
I know. But as its the only documentation available for the object, its
what I have to work with.
Post by JJ
Just follow example code in that page and treat the control as
if it's an array of objects. See below page if you're still confused.
This time its you who is confused I'm afraid: I'm using VBScript (as per
this newsgroups name), not Visual Basic. :-)

Regards,
Rudy Wieser
Post by JJ
Post by R.Wieser
Hello all,
After having figured out my previous problem (not getting events) I almost
directly bumped into another one: Imagine a simple HTTP server, which
should be able to handle several requests at a time. Almost directly a few
problems pop-up. Googeling for
1) How do I get a single listening socket to "spawn" multiple data
sockets -- the standard method of closing the listening socket down and than
accepting the new connection on the now-free socket would, AFAICS, cause
other waiting connection-requests to be dropped. Which is double-plus
non-good.
Accept the connection, but do further processing on it at later time using a
timer. The important thing is to let the VBScript enters the idle state so
that any pending connection events can be passed to the VBScript by the
Winsock OCX.
Post by R.Wieser
2) How do I get to share the events for the different data-sockets ? --
Although MSDN* tells me that the MSWinsock control should be able to work
as/in a "control array" and the connectionRequest event supposedly has an
"index" argument, looking at the typelib exposed by the MSWinsck.ocx
control** I have here I can't discover the first (no index property) nor the
second (the connectionRequest event shows it has only got a single argument
(supposedly the connectionID) )
* https://msdn.microsoft.com/en-us/library/aa733709(v=vs.60).aspx
** v6.0 SP5.
TL;DR: Does someone have an example handy which shows the basics of a
multi-connection MSWinsock server for a Win98se environment ? I could
surely use one -- if only to figure out how the different parts play
together.
Type Library is only for a reference for applications which don't know what
members are available in a COM interface, or need to know what interface and
their members are available. It's not really a requirement. Any COM/ActiveX
can be fully functional even if it doesn't have embedded or external Type
Library. COM/ActiveX modules are the one that validate whether an interface
member name is available or not, not the application that use them.
Just follow example code in that page and treat the control as if it's an
array of objects. See below page if you're still confused.
<http://www.devx.com/tips/Tip/5488>
Mr. E
2017-04-14 04:55:07 UTC
Permalink
Post by R.Wieser
Hello all,
After having figured out my previous problem (not getting events) I almost
directly bumped into another one: Imagine a simple HTTP server, which
should be able to handle several requests at a time. Almost directly a few
problems pop-up. Googeling for
...
TL;DR: Does someone have an example handy which shows the basics of a
multi-connection MSWinsock server for a Win98se environment ? I could
surely use one -- if only to figure out how the different parts play
together.
After a similar fight with MSWinsock a few years ago I moved to SocketWrench. Version 6.0 is free unlimited time for personal use. I have use it under XP, win 7 and 10. I use it for a basic HTTP and file server as well as web based control of some home automation. (Web <-> pc <-> Bluetooth lights and security etc.)

NOTE: It to use SocketWrench 6.0 with VBS it seems you need to have some version of visual basic installed for some MS license?? (community version is ok) My code is pure VBS not VB, the install is ONLY for the license.

Mr. E

---
This email has been checked for viruses by AVG.
http://www.avg.com
R.Wieser
2017-04-14 07:12:56 UTC
Permalink
Mr. E,
Post by Mr. E
After a similar fight with MSWinsock a few years ago I moved
to SocketWrench.
I take from that you where (also) unsuccessfull in finding a working
solution.

Its not so much that I need another socket object*, but am seriously
wondering if either I am/where missing some info to make it work, or that
the MSWinSock component is (rater intentionally if you ask me) crippeled to
allow only a single connection at any time.

*have been tinkering in that direction myself. :-)

An extra problem and a show-stopper to me: to accept a connection means you
have to switch off listening mode, dropping all other posibly present
requests and stay "deaf" for the duration of handling the accepted
connection. That won't work when the HTML page contains *any* kind of
resource that also needs to be retrieved.

On the other hand, it could not hurt to take a peek at that "socketwrench"
object ...

Regards,
Rudy Wieser

P.s.
"This email has been checked for viruses by AVG."
Thats fine-and-dandy, but how many did it find ? :-p
Post by Mr. E
Hello all,
After having figured out my previous problem (not getting events) I almost
directly bumped into another one: Imagine a simple HTTP server, which
should be able to handle several requests at a time. Almost directly a few
problems pop-up. Googeling for
...
TL;DR: Does someone have an example handy which shows the basics of a
multi-connection MSWinsock server for a Win98se environment ? I could
surely use one -- if only to figure out how the different parts play
together.
After a similar fight with MSWinsock a few years ago I moved to
SocketWrench. Version 6.0 is free unlimited time for personal use. I have
use it under XP, win 7 and 10. I use it for a basic HTTP and file server as
well as web based control of some home automation. (Web <-> pc <-> Bluetooth
lights and security etc.)

NOTE: It to use SocketWrench 6.0 with VBS it seems you need to have some
version of visual basic installed for some MS license?? (community version
is ok) My code is pure VBS not VB, the install is ONLY for the license.

Mr. E

---
This email has been checked for viruses by AVG.
http://www.avg.com

Loading...