Solved

Que Sockets sockets... a question..

Posted on 1998-08-13
3
226 Views
Last Modified: 2013-11-20
Hi guys,
   I have a question ( don't we all.. :)) First, the story:
I am trying to use MFC sockets to connect to 2 different servers using TCP/UDP from a MFC application..
The app. originally had a single connection and it worked fine. I integrated the code for the second connection
and the code for both of them are similar...
           call WSAStartup(..,.. ) // only called once per application
           // the part below appears for each connection ie. twice in different .cpp
           m_socket = socket (.....
          sockaddr.sin_family  = .....
          the rest...    

Well, after the integration, there was some network connection error...
I solved it !!!!! But I had to add (A) #include <afxsock.h> in stdafx.h   and had to comment out this line:
(B) if (! AfxSocketInit()) .... in MyApp::InitInstance ( which was part of my 2nd connection code example )
MY question is :
1. Why did the 1 connection (b4 changes) version work fine when I didn't add (A) and
2. Why did I have to comment out the code as in (B)?
That's it... I just want to know the reasons...

Thanks.

David Chong


0
Comment
Question by:Haho
  • 2
3 Comments
 

Accepted Solution

by:
zingo earned 100 total points
ID: 1320721
It seems to me that you are mixing different kinds of socket implementations here.

AfxSocketInit() should be called, I think, when you use the MFC socket classes, CAsyncSocket (which I recommend) et cet. WSAStartup should be called when you use the ordinary Win32 socket functions, like socket(), send() et cet.

What AfxSocketInit does is that it calls WSAStartup, so you are actually doing it twice.

So, decide to use MFC or Win32.

If you use the AppWizard to create your application, you can put a cross in the box for WOSA Sockets, and then you get the modification to StdAfx.h and MyApp::InitInstance for free. Then use MFC sockets, it is much simpler.
0
 
LVL 1

Author Comment

by:Haho
ID: 1320722
Thanks...

    a bit more explaination would be nice....  

 Bye!!
  David Chong


0
 

Expert Comment

by:zingo
ID: 1320723
On what topic? How to use MFC sockets?
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
no14 challenge 14 72
FizzBuzz challenge 9 83
Detect file exist or not 3 198
Remove Password Protection from pdf (with password) using an command line executable 5 77
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question