Sockets with Threads ?!? 
Author Message
 Sockets with Threads ?!?

Hi all!

I need help with VB programming - sockets:
I wrote a java app which handles socket communications, and for that
runs a socket "listener" as a threads, which runs another function
according to the socket input.
Now, I'm trying to convert the app to VB. How can I handle socket
communication in VB? Also with threads? And if so, how do I create
threads? Is it simple to maintain?
Please, I need help...

Thanks,
Aviv.



Mon, 31 Jan 2000 03:00:00 GMT  
 Sockets with Threads ?!?

Hello,

VB versions 4.0 and lower do not have ANY support for multithreading.  VB
5.0 supports COM Apartment Model multithreading of COM servers that are
marked for unattended execution.  These servers MUST not expose any user
interface (i.e. forms, messages boxes, etc.).  VB 5.0 also now supports
Callback functions so you can use multithreading using the Win32 API
directly as well.  Look for an article in Visual Basic Programmer's Journal
May 1997 issue (Vol. 7, No. 6) called "Create Multithreaded Object" by
Ibrahim Malluf.  It has a fairly complete explanation of Apartment Model
Threading with VB objects.  For API threading, check out VBPJ's July 1997
issue (Vol. 7 No 8).  The "Black Belt Programming" column has an article
called "Give Your Code Some New Threads" by Hank Marquis.  He builds a
simple CThread class that you can use to create threads in VB 5.0.

As far as VB's support for sockets, again not much.  VB 4.0 and below did
not ship with any sockets support.  VB 5.0 ships with a Winsock control that
can be used to create TCP or UDP applications.  Big problem:  This is an
ActiveX control, so if you want to use it, it must be placed on a form.  As
you can see from paragraph one above, this means that you can't use this
control (or multiple instances of this control) in multiple threads, since
the control requires a control container to operate.

But, since VB 5.0 does support callbacks, you can author a Winsock 2
application using the Win32 Winsock 2.0 API.  You can also write a Winsock
1.1 application, but you'll need to subclass the window so you can get
access to the Window procedure so you can intercept the messages sent by
sockets operating in Async. mode (if you plan to use blocking or
non-blocking mode, you can avoid subclassing).  To help with this, you can
get a freeware control from Mabry Software called MsgBlaster or something
like that.  It will do the subclassing for you, but it is a control, so see
paragraph one for problems with using it.

So, the long and the short of this is:  VB is great for making single
threaded, client applications that use TCP or UDP (VB 5.0 that is), but if
you need a multithreaded server application, then you're going to spend so
much time making API calls, that you should probably write the application
in C or C++ anyway.

My two cents, for what it's worth.  I hope this helps.

--

Larry Tubbs, MCPS, MCSD
Silverleaf Vacation Club

http://www.geocities.com/ResearchTriangle/5727/


Quote:
>Hi all!

>I need help with VB programming - sockets:
>I wrote a java app which handles socket communications, and for that
>runs a socket "listener" as a threads, which runs another function
>according to the socket input.
>Now, I'm trying to convert the app to VB. How can I handle socket
>communication in VB? Also with threads? And if so, how do I create
>threads? Is it simple to maintain?
>Please, I need help...

>Thanks,
>Aviv.



Mon, 31 Jan 2000 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Sockets with Threads ?!?

2. Sockets with Threads ?!?

3. Asynchronous Socket thread safty question.

4. Socket Asynchronous CallBack Function in thread

5. SOCKET : Receiving and sending in different threads

6. Socket callbacks and lots of threads!

7. Trouble with System.Net.Sockets.Socket under Windows 98

8. System.Net.Sockets.Socket Problem

9. System.Net.Sockets.Socket State

10. system.net.sockets.socket async server example

11. Detect Remote Disconnection System.Net.Sockets.Socket

12. System.Net.Sockets.Socket.EndReceive has a bogus return value

 

 
Powered by phpBB® Forum Software