Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

MFC Socket programming

Posted on 2003-11-18
7
Medium Priority
?
2,436 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
Technology Partners: 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 200 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

Tech or Treat! - Giveaway

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

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…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…

610 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