HackerJLY's Blog

我不是一个真正的程序员!没有编写过一个真正的程序,整天在写“伪代码”!我只是一个打杂的!- 2008.02.29_0:05

用户操作
[即时聊天] [发私信] [加为好友]
Jackie JiID:HackerJLY
12699次访问,排名9110好友61人,关注者63
C,C++,API,MFC,VB6,Win32_ASM,C#,SQL,JavaScript,HTML
HackerJLY的文章
原创 26 篇
翻译 0 篇
转载 66 篇
评论 2 篇
Jackie Ji的公告
初级程序员用VB !
高级程序员用Delphi !
真正的程序员用C++ !

web 
page counters
Leave a message to me with QQ?
Google


最近评论
moomee:初级程序员用VB !
高级程序员用Delphi !
真正的程序员用C++ !


我最开始学VB
后来因为实习单位所以就学Java
经过了一段时间迷茫后,我决定今后学习C++和汇编。

帮你补充一下,真正的程序员用的是C++和汇编。
PrideRock:Good
文章分类
收藏
    相册
    My Other Blog
    HackerJLY - CSDN 下载频道
    HackerJLY's Blog - BlogSpot.com
    HackerJLY's Blog - CNBlogs.com
    HackerJLY's Blog - CNXHacker.net
    HackerJLY's Blog - HackBase.com - 黑基
    HackerJLY's Blog - MSN(RSS)
    HackerJLY's Google Page
    HackerJLY's Source - CSDN
    HackerJLY's 个人空间 - CSDN
    HackerJLY's 网摘 - CSDN
    Study(学习)
    Tree - MSDN Library
    Tree - MSDN 技术资料库
    存档
    软件项目交易
    订阅我的博客
    XML聚合  FeedSky
    订阅到鲜果
    订阅到Google
    订阅到抓虾
    订阅到BlogLines
    订阅到Yahoo
    订阅到GouGou
    订阅到飞鸽
    订阅到Rojo
    订阅到newsgator
    订阅到netvibes

    转载 Windows Sockets: Sequence of Operations(操作顺序) - MFC_CAsynSocket收藏

    新一篇: VC++ 6.0 Glossary - VC++ 6.0 术语表 - From MSDN | 旧一篇: Windows Sockets: Socket Notifications

    Windows Sockets: Sequence of Operations

    HomeOverviewHow Do ISample

    This article illustrates, side by side, the sequence of operations for a server socket and a client socket. Because the sockets use CArchive objects, they are necessarily stream sockets.

    Sequence of Operations for a Stream Socket Communication

    Up to the point of constructing a CSocketFile object, the following sequence is accurate (with a few parameter differences) for both CAsyncSocket and CSocket. From that point on, the sequence is strictly for CSocket. The following table illustrates the sequence of operations for setting up communication between a client and a server.

    Setting Up Communication Between a Server and a Client

    Server Client
    // construct a socket

    CSocket sockSrvr;

    // construct a socket

    CSocket sockClient;

    // create the SOCKET

    sockSrvr.Create(nPort);1,2

    // create the SOCKET

    sockClient.Create( );2

    // start listening

    sockSrvr.Listen( );

     
      // seek a connection

    sockClient.Connect(strAddr, nPort);3,4

    // construct a new, empty socket

    CSocket sockRecv;

    // accept connection

    sockSrvr.Accept( sockRecv ); 5

     
    // construct file object

    CSocketFile file(&sockRecv);

    // construct file object

    CSocketFile file(&sockClient);

    // construct an archive

    CArchive arIn(&file,          CArchive::load);

     -or-

    CArchive arOut(&file,          CArchive::store);

      – or Both – 

    // construct an archive

    CArchive arIn(&file,          CArchive::load);

    -or-

    CArchive arOut(&file,          CArchive::store);

     – or Both – 

    // use the archive to pass data:

    arIn >> dwValue;

    -or-

    arOut << dwValue;6

    // use the archive to pass data:

    arIn >> dwValue;

    -or-

    arOut << dwValue;6

    1. Where nPort is a port number. See Windows Sockets: Ports and Socket Addresses for details about ports.

    2. The server must always specify a port so clients can connect. The Create call sometimes also specifies an address. On the client side, use the default parameters, which ask MFC to use any available port.

    3. Where nPort is a port number and strAddr is a machine address or an Internet Protocol (IP) address.

    4. Machine addresses can take several forms: “ftp.microsoft.com”, “ucsd.edu”. IP addresses use the “dotted number” form “127.54.67.32”. The Connect function checks to see if the address is a dotted number (although it doesn’t check to ensure the number is a valid machine on the network). If not, Connect assumes a machine name of one of the other forms.

    5. When you call Accept on the server side, you pass a reference to a new socket object. You must construct this object first, but do not call Create for it. Keep in mind that if this socket object goes out of scope, the connection closes. MFC connects the new object to a SOCKET handle. You can construct the socket on the stack, as shown, or on the heap.

    6. The archive and the socket file are closed when they go out of scope. The socket object’s destructor also calls the Close member function for the socket object when the object goes out of scope or is deleted.

    Additional Notes About the Sequence

    The sequence of calls shown in the preceding table is for a stream socket. Datagram sockets, which are connectionless, don’t require the CAsyncSocket::Connect, Listen, and Accept calls (although you can optionally use Connect). Instead, if you’re using class CAsyncSocket, datagram sockets use the CAsyncSocket::SendTo and ReceiveFrom member functions. (If you use Connect with a datagram socket, you use Send and Receive.) Because CArchive doesn’t work with datagrams, don’t use CSocket with an archive if the socket is a datagram.

    CSocketFile doesn’t support all of CFile’s functionality; CFile members such as Seek, which make no sense for a socket communication, are unavailable. Because of this, some default MFC Serialize functions aren’t compatible with CSocketFile. This is particularly true of the CEditView class. You should not try to serialize CEditView data through a CArchive object attached to a CSocketFile object using CEditView::SerializeRaw; use CEditView::Serialize instead (not documented). The SerializeRaw function expects the file object to have functions, such as Seek, that CSocketFile does not support.

    What do you want to know more about?

    See Also   CSocket, CAsyncSocket::Create, CAsyncSocket::Close

    发表于 @ 2008年06月14日 18:07:24|评论(loading...)|编辑|收藏

    新一篇: VC++ 6.0 Glossary - VC++ 6.0 术语表 - From MSDN | 旧一篇: Windows Sockets: Socket Notifications

    评论:没有评论。

    发表评论  


    登录
    Csdn Blog version 3.1a
    Copyright © Jackie Ji