15 мая 2023 года "Исходники.РУ" отмечают своё 23-летие!
Поздравляем всех причастных и неравнодушных с этим событием!
И огромное спасибо всем, кто был и остаётся с нами все эти годы!

Главная Форум Журнал Wiki DRKB Discuz!ML Помощь проекту


Using CSocket in a multithread

Ahmed
Monday, October 21, 1996


Environment: Window NT 4.0, VC++ 4.2

Hi,

I want to start a listenning socket in a new thread other than the main   
UI thread.
My problem is the listening socket dosen't get any sockets notifications.
Any help in this regard would be appreciated.

Thanx

A.S





Phil Daley -- pdaley@relay.com
Tuesday, October 22, 1996

[Mini-digest: 4 responses]

At 12:18 PM 10/21/96 -0400, you wrote:

=====================================

>

>Environment: Window NT 4.0, VC++ 4.2

>

>I want to start a listenning socket in a new thread other than the main   

>UI thread.

>My problem is the listening socket dosen't get any sockets notifications.

>Any help in this regard would be appreciated.

>

==================================


I don't understand.  I think you need to give more information.


Do you create and bind the socket in the main thread and then pass it to the new thread to listen?


Or is everything done in the new thread?


Is it a blocking socket?


Does it work if everything is in the main thread?




8080,0000,8080Phil Daley         
Relay Technology

8080,0000,8080http://www.conknet.com/~p_daley



-----From: "Dan Maher" 

Your thread must have a message pump for it to get notifications.  The MFC
socket classes create a hidden window to receive messages.  Without a
message pump, no messages are processed and you won't get notifications. 
Also, make sure that your socket is created on the thread that will be
processing the notifications.  Otherwise, MFC will create the "hidden"
notification window on the wrong thread and you will end up with a
performance bottleneck there.

dM
-----From: "George Pavlou" 

You can use the  WSAAsyncSelect(hsocket, hWnd, WSA_READ, FD_READ |
FD_CLOSE) 
which sends a WSA_READ message.

 |--------------------------------------------------------------------------
|
   George Pavlou                           Tantalus, Inc.            
   Windows Games Programmer     Key West, FL       
   georgep@tansoft.com                 www.mpgn.com 
 |--------------------------------------------------------------------------
|

-----From: "Luke Stephens" 

Are you using a CWinThread or just a worker thread?
You must have a user interface thread (CWinThread) in order for  it to work
properly.

Luke Stephens
luker@tfs.net




Doug Boone -- dboone@fasttax.com
Wednesday, October 23, 1996

[Mini-digest: 2 responses]

What's your logic for starting the threads? For starting the sockets? Do
you start the threads which create the socket and then the wait on listen?
Are you using CSocket or CAsyncSocket? What's your favorite color?  

----------
> From: Sadek, Ahmed 
> To: 'mfc-l' 
> Subject: Using CSocket in a multithread
> Date: Monday, October 21, 1996 11:18 AM
> 
> 
> Environment: Window NT 4.0, VC++ 4.2
> 
> Hi,
> 
> I want to start a listenning socket in a new thread other than the main  

> UI thread.
> My problem is the listening socket dosen't get any sockets notifications.
> Any help in this regard would be appreciated.
> 
> Thanx
> 
> A.S
> 
-----From: "Hill, Les" 

The key is to NOT use CAsynchSocket::Accept().

Use ::accept() to get the new socket handle.  Then pass this to the worker 
thread (perhaps as a member variable).  Inside the worker thread use 
CSocket::Attach() to
bind the CSocket object to the new socket handle -- this creates the hidden 
window properly.

Les Hill
leh@cybercom.net
Available for contract programming





| Вернуться в корень Архива |