Solved

Que Sockets sockets... a question..

Posted on 1998-08-13
3
220 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
Comment Utility
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
Comment Utility
Thanks...

    a bit more explaination would be nice....  

 Bye!!
  David Chong


0
 

Expert Comment

by:zingo
Comment Utility
On what topic? How to use MFC sockets?
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Need a Shell script to start a service checking the port 6 46
NotAlone Challenge 20 70
scoreUp challenge 14 47
Change to event 1 72
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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 this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

762 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now