|
-
April 23rd, 2001, 02:29 PM
#1
Multithreading & Winsock
I know multithreading in VB or even VC++ has been hot topics recently. I am trying to write an application which uses winsock technology to implement a tcp/ip server. I want to accept non-blocking connections on several different protocols such as TELNET, FTP, NNTP, SMTP, etc... Can someone explain to me how this can be done in VB if possible.
Thanks!
Chris Cranford
-
April 23rd, 2001, 07:55 PM
#2
Re: Multithreading & Winsock
in order to implement non-blocking, you will need to use winsock version 2, which provides a sub-set of API specially for asyn (non-blocking) connection. refer MSDN, winsock programming.
I did one with MFC CAsyncSocket, however, if u do multithreading, then u wouldn't bother whether it's non-blocking or blocking as you will have another thread for reading the data.
Anyway, back to VB, the simple way to do non-blocking connection is using Winsock control. I did use it for POP3, SMTP programming. you can find sample in vbPop3 in vbLib (http://vblib.virtualave.net). However, it's only tested in my server as I use it to check, send & receive mail. In order to implement FTP, Telnet, you will need rfc on it, where you can find from http://www.freesoft.org/CIE/RFC/. In vblib.virtualave.net, here is a sample in multithreading (section work in progress), but, beware, you just need to be more careful in program multithreading program.
HTH
-
April 23rd, 2001, 08:33 PM
#3
Re: Multithreading & Winsock
The way that I am trying to write my program is 1 thread per connection. Therefore, each thread will be responsible for Reading and Sending of data. Therefore, it would be important to use Asyncronous sockets so that events can be fired when data comes in or when data needs to be sent to the remote system. (bidirectional).
The multithreading example on that website, is there a way I could get a copy of the source for vbLibDll.Dll? I would like to make some modifications but would be willing to credit the author for their code ...
Thanks!
Chris Cranford
-
April 23rd, 2001, 08:50 PM
#4
Re: Multithreading & Winsock
as u can see from the work in progress section, I got it into a class vbMultiThreading, which doesn't use the vbLibDll anymore, please send me ur email, and I will send it to u.
-
April 23rd, 2001, 08:53 PM
#5
Re: Multithreading & Winsock
[email protected] is the email address. Let me ask you, how will I be able to implement winsock using this class method? Now the only question I have is whether there is a way to implement winsock using your vbMultithreading class?
Thanks!
Chris Cranford
-
April 23rd, 2001, 09:14 PM
#6
Re: Multithreading & Winsock
what u need to do is declare a function in module (not class module) like this
public function test(param as long) as long
winsock function for receiving data .....
end function
handle = vbMultiThreading.RunThread(Addressof test)
remember to save the handle for terminating the thread.
but, multithreading in vb is really not proven, if not, microsoft would have implement it, don't really have to wait until VB.Net.
I haven't used that class for any program yet, as I am more keen to use VC++ MFC for multithreading program. And as a matter of fact, winsock control in VB doesn't need any multithreading in order to do Async winsock, why bother implement it yourself ?? If u look at the vbPop3 class, it's really an Async class and I got it work with my server. So, If I use VB, I rather use winsock control and forget about all those troublesome stuff.
HTH
hope u receive the class file already
-
April 23rd, 2001, 09:18 PM
#7
Re: Multithreading & Winsock
It's important that my server be able to accept multiple connections for a particular port. I need to be able to accept like 16 TELNET concurrent sessions without 1 connection blocking or suspending or causing a timeout on another connection (such as sending/receiving files). understand why I need multithreading?
Thanks!
Chris Cranford
-
April 23rd, 2001, 09:26 PM
#8
Re: Multithreading & Winsock
yap, I understand now. u want to listen to a socket and create extra socket for individual connection, I guess.
Anyway, I hope I have gave u some hints on doing that.
-
April 23rd, 2001, 09:37 PM
#9
Re: Multithreading & Winsock
Is there anyway to pass winsock information between threads in Visual Basic?
Thanks!
Chris Cranford
-
April 23rd, 2001, 09:56 PM
#10
Re: Multithreading & Winsock
declare public variable in module and it will be accessible to several threads. e.g.
global i as long
assume you got two threads,
public function test(param as long) as long
you can use i here ...
end function
public function test2(param as long) as long
you can use i here also...
end function
it might not work because of vb apartment-thread model, i am not sure, but i used it before, it seems to work.
HTH
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|