Solved

Que Sockets sockets... a question..

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VBA "SendKeys" Syntax for Multiple Keystrokes 7 117
ShiftLeft challenge 21 86
scoreUp challenge 14 64
Problem to Office 1 15
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

831 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