Solved

Que Sockets sockets... a question..

Posted on 1998-08-13
3
224 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

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
mixString challenge 36 122
bigDiff challenge 17 106
Line meaning 9 86
unix example issues 18 90
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
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.
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

772 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