Solved

Que Sockets sockets... a question..

Posted on 1998-08-13
3
222 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 Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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…
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 Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
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.

863 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

25 Experts available now in Live!

Get 1:1 Help Now