Solved

MFC Socket programming

Posted on 2003-11-18
7
2,405 Views
Last Modified: 2013-11-20
Hi,

I am building an MFC ActiveX control which can handle TCP/IP communication. Which class is usually used, CAsyncSocket or CSocket? I don't like the CArchive since the another end of the communication is not MFC necessary. I would appreciate any good online resource or simple example. Thanks.

Cindy
0
Comment
Question by:CindyZhou
7 Comments
 
LVL 6

Expert Comment

by:Triskelion
ID: 9772252
What type of transactions will your socket be doing?
0
 
LVL 5

Expert Comment

by:jrocnuck
ID: 9772264
0
 

Author Comment

by:CindyZhou
ID: 9772312
Thank you, jrocnuck.

I checked with these samples already. But the chatter sample uses CArchive, which is not good when the other side is not MFC application.  Am I right or what?
0
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.

 
LVL 48

Expert Comment

by:AlexFM
ID: 9773484
CSocket is very simple for using, but it is synchronous. If you are beginner, use CSocket. If you want to do professional application, use CAsyncSocket or sockets API.
My favorite sockets sample is:

http://www.codeproject.com/internet/winsockiocp.asp

It is not simple, but it shows how to build professional sockets communications using multithreading and non-blocking calls.
0
 
LVL 5

Accepted Solution

by:
jrocnuck earned 50 total points
ID: 9775079
CSocket is derived from CAsyncSocket, so it has all the capabilities of CAsyncSocket.  By default it is a blocking socket.  You have to call IOCTL functions to make it non blocking.

As far as the CArchive is concerned, you just remove that from the chatter sample..

basically (THIS EXAMPLE HAS NO ERROR CHECKING) you do something like this for the client:

CSocket mySocket;
UCHAR pBuffer[1024]; // data buffer
mySocket.Create( SOCK_STREAM ); // TCP socket

mySocket.Connect( "196.198.0.1", 80 ) )
// connected to server at 196.198.0.1 on port 80
sprintf( (char *) pBuffer, "Hello server!\0" );
mySocket.Send( pBuffer, 14, 0 );

mySocket.Close();
----------------------------------------------------
and for the server:

int nBytesReceived;
UCHAR pBuffer[1024];
CSocket myListenSocket;
CSocket myActiveSocket;

myListenSocket.Create( 80, SOCK_STREAM, 0 );
myListenSocket.Listen(0);
myListenSocket.Accept( myActiveSocket );
myListenSocket.Close(); // don't listen for any more connections (unless you want to)
nBytesReceived = myActiveSocket.Receive( pBuffer, 1024, 0 );
printf( "Received %d bytes, msg: %s\n", nBytesReceived, (char *)pBuffer );
myActiveSocket.Close();
0
 

Expert Comment

by:senthil_kumar1980
ID: 10493413
hai,  

       I want to send more than 80000 bytes of data using multicast socket .I can't send these much of data in multicast socket.Any one please help me immediately.I think we can set using SO_SNDBUF ,But I don't know how to set these in setsocketopt.Please i am waiting for reply.


                   Thank You,
                                                By,
                                        R.Senthilkumar.
0
 
LVL 5

Expert Comment

by:jrocnuck
ID: 10495500
post it as an official question so you can give points for the answer...

and post the link to the question here.
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

Title # Comments Views Activity
Installing Microsoft R server on REDHAT or SUSE Linux 4 131
iSeries FTP Exit Program 8 122
ODBC Connection Logging, ADO.NET 6 54
Named range not carried over 10 61
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 …
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.
I designed this idea while studying technology in the classroom.  This is a semester long project.  Students are asked to take photographs on a specific topic which they find meaningful, it can be a place or situation such as travel or homelessness.…

939 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

10 Experts available now in Live!

Get 1:1 Help Now