Solved

MFC Socket programming

Posted on 2003-11-18
7
2,423 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

705 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