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

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


How to establish second CSocket connection?

MICHAEL@datatree.com
Sunday, August 25, 1996

Environment: VC++ 4.2, Win95 and TCP/IP network

I use the doc-view classes created by AppWizard for
my first CSocket. Then I create a second CDocument
class for a separate, or second, CSocket class.

This second CDocument class is initialized by calling
OnNewDocument, which then calls my MakeConnection
function. My program hangs in "MFC Land" (SockCore.cpp)
when executing PumpMessage(FD_CONNECT).

To the best of my knowledge, my program seems to create,
instantiate and initialize the second CDocument just like the
first, but only the first will allow me to connect.

Any ideas?


Michael Thal        michael@datatree.com                              
Data Tree Corp.     http://www.datatree.com





Bradley A. Burns -- bburns@sprynet.com
Sunday, August 25, 1996

[Mini-digest: 3 responses]

Hi there, Michael...

I've had the same problem before and just got something relatively working
about 30 seconds ago! I believe that the problem could be with the
document having the CSocket embedded within it. To my knowledge, the
CSocket class (and associated socket classes) do not have copy
constructors. (At least, that's the what was giving me a problem.) Try
maintaining a CPtrList or CObList of your CDocument derrived class. I
think this may help. Also, there is an article in the February 1996 MSJ
called, "Write a Simple HTTP-based Server Using MFC and Windows Sockets"
by David Cook.  The article shows how to embed a CSocket class within a
CDocument class using a CPtrList.

Bradley A. Burns
bburns@sprynet.com

----------
> From: michael 
> To: mfc-l@netcom.com
> Subject: How to establish second CSocket connection?
> Date: Sunday, August 25, 1996 7:19 AM
> 
> Environment: VC++ 4.2, Win95 and TCP/IP network
> 
> I use the doc-view classes created by AppWizard for
> my first CSocket. Then I create a second CDocument
> class for a separate, or second, CSocket class.
> 
> This second CDocument class is initialized by calling
> OnNewDocument, which then calls my MakeConnection
> function. My program hangs in "MFC Land" (SockCore.cpp)
> when executing PumpMessage(FD_CONNECT).
> 
> To the best of my knowledge, my program seems to create,
> instantiate and initialize the second CDocument just like the
> first, but only the first will allow me to connect.
> 
> Any ideas?
> 
> 
> Michael Thal        michael@datatree.com                              
> Data Tree Corp.     http://www.datatree.com
> 
-----From: Marty Halvorson 

    Are you trying to connect to the same port as the other socket?
    Have you made sure the destination address is valid?

    There really isn't enough information in your question to offer any other
    ideas.  So, my guess would be that: the destination is not responding to
    the connection request and you're code is waiting for the response.


    Peace

			Marty Halvorson
			marty@lanl.gov

-----From: "michael" 

I was able to solve my multiple socket problem.

Basically, my problem was trying to get two CSocket objects in
the same application to connect simultaneously - each to a separate
PC on a TCP/IP network.

Unfortuantely, I was not aware that the first socket blocks the second
because it is a CSocket object rather than a CAsyncSocket - which
allows blocking to be disabled.

A brief description of my new approach follows:
----------------------------------------------------------------------------
--------------
Environment: Three PCs are connected over a TCP/IP network.

Note: PC#2 listens to PC#1. When it receives certain messages
it connects to PC#3 and sends a mesage to it.

The program I'm developing resides in PC#2 and uses one
socket object to listen to PC#1 and a second socket object
to connect to PC#3.

The problem lies in the fact that if both sockets are derived
from CSocket, then PC#2 is blocked from connecting to PC#3,
because it is already listening to PC#1.

So, my compromise is to derive the listening socket from
CAsyncSocket instead of CSocket and turn blocking off.

Michael Thal        michael@datatree.com                              
Data Tree Corp.     http://www.datatree.com





MICHAEL@datatree.com
Thursday, August 29, 1996

Please disregard my previous solution posted by MFC-L
on August 25th. 

I stumbled across the REAL solution to the problem I was
having getting a second CSocket object to connect
while a separate CSocket object was listening.

I took over the socket application from anothe programmer,
who left the company.  She had a timer active!

See Knowledge Base Article Q154649 "CSocket Operation
Hangs if a Timer is Active".

I turned the timer off and viola!  I was able to connect.

>Environment: VC++ 4.2, Win95 and TCP/IP network
>
>I use the doc-view classes created by AppWizard for
>my first CSocket. Then I create a second CDocument
>class for a separate, or second, CSocket class.
>
>This second CDocument class is initialized by calling
>OnNewDocument, which then calls my MakeConnection
>function. My program hangs in "MFC Land" (SockCore.cpp)
>when executing PumpMessage(FD_CONNECT).
>
Michael Thal           michael@datatree.com
Data Tree Corp.     http://www.datatree.com





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