Solved

MFC Socket programming

Posted on 2003-11-18
7
2,413 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
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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.

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Looking for a specific application/software 2 114
conditional code and condition difference 9 84
move a line in eclipse 3 107
unix example issues 18 98
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
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.
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

856 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