Solved

MFC Socket programming

Posted on 2003-11-18
7
2,401 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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

744 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