CodeGuru Forums -
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic Newsletters VB Forums Developer.com


Newest CodeGuru.com Articles:

  • Faltering Windows support
  • Internet Explorer 8 Click Clever Click Safe
  • Release Candidate 2 for ASP.NET MVC 2
  • Learn How to Create Dual Mode Windows Services

  • Search CodeGuru:
     



    Go Back   CodeGuru Forums > CodeGuru Technical FAQs > CodeGuru Individual FAQs
    FAQ Members List Calendar Search Today's Posts Mark Forums Read

    CodeGuru Individual FAQs The indivdual FAQs for CodeGuru. See the specific Topic FAQ forums for index pages and links to these Frequently Asked/Answered Questions.

    Reply
     
    Thread Tools Search this Thread Display Modes
      #1    
    Old January 30th, 2005, 12:44 AM
    MikeAThon MikeAThon is offline
    Elite Member
    Power Poster
     
    Join Date: Nov 2002
    Location: California
    Posts: 4,124
    MikeAThon has a brilliant future (2000+) MikeAThon has a brilliant future (2000+) MikeAThon has a brilliant future (2000+) MikeAThon has a brilliant future (2000+) MikeAThon has a brilliant future (2000+) MikeAThon has a brilliant future (2000+) MikeAThon has a brilliant future (2000+) MikeAThon has a brilliant future (2000+) MikeAThon has a brilliant future (2000+) MikeAThon has a brilliant future (2000+) MikeAThon has a brilliant future (2000+)
    Visual C++ Network: Where can I find examples of socket programs?

    Q: Where can I find examples of socket programs?

    A: MSDN has a few good examples. Although these all are based on the MFC 'CAsyncSocket' classes, they should serve as guidance even if you are not using these classes. The URLs are current as of January 2005:

    • "Message-Oriented TCP and Multithreaded Client/Server"

      'MFCAsync.exe' contains a Visual C++ 5.0 project sample that shows the communication techniques between a client ('AsyncClient') and a server ('AsyncServer') application using MFC 'CAsyncSocket' class on each sides.


    • "MSocUdp.exe Implement UDP Using CAsyncSocket"

      The 'MSocUdp' sample is a minimal dialog box-based MFC application that demonstrates how to use the CAsyncSocket class to send and receive directed datagram or broadcast datagram over User Datagram Protocol (UDP).


    • "MultiSoc: Illustrates Using Sockets in Multiple Threads"

      This sample illustrates how to pass a socket connection between threads in an MFC application. The sample consists of two projects, the Server and the Client. The server creates a new thread for each connection to communicate with the client.


    • "MFCSocs.exe Avoids Two Common MFC Socket Mistakes"

      The 'MFCSocs' sample is a minimal MFC application that demonstrates how to use the 'CSocket' and 'CAsyncSocket' classes to communicate in a Transmission Control Protocol (TCP) connection. This sample is a dialog-based application. Depending on the selection in the user interface, the application can run either as a TCP server that listens on a certain TCP port, or as a client that connects to a server on the same TCP port. This sample also addresses two common mistakes that MFC socket programmers can make:

      • Issuing more than one 'Receive' call in the 'OnReceive' notification function and
      • Not issuing enough 'Send' calls to make sure all data has been sent when using the 'CAsyncSocket::Send' function


    • "CHATTER Sample: Demonstrates a Windows Sockets Client Application"

      'CHATTER' is a Windows Sockets Client sample application. It is a single document interface (SDI) application with a splitter window that lets the user send messages to a discussion server ('CHATSRVR', next below), which in turn sends them to multiple other 'CHATTER' users simultaneously.


    • "CHATSRVR Sample: Demonstrates a Windows Sockets Server"

      'CHATSRVR', a Windows Sockets Server sample application, is a single document interface (SDI) application that implements a discussion server for clients of the 'CHATTER' sample (directly above).


    • "Write a Simple HTTP-based Server Using MFC and Windows Sockets"

      'Webster' is the Yugo of Web servers. It offers only minimal HTTP support with no frills. 'Webster' only handles GET requests, and it doesn't do anything with most of the extra client information it receives, like the If-Modified-Since field. But 'Webster' does illustrate the basic features common to every Web server, including very powerful servers like Microsoft Internet Information Server. 'Webster' is good enough to present your very own real live Web home page, and it does run on both Windows 95 and Windows NT. (From the February 1996 issue of Microsoft Systems Journal (predecessor of MSDN Magazine))

    If you are looking for examples that are mostly based on pure Berkeley sockets (which includes Winsock and Unix/Linux flavors of that library), then here are some good examples. All use basic functionality of a much older version of Winsock (version 1.0) and therefore none rely on advanced functionality (like event-based triggers) provided by the current version of Winsock (version 2.2.2). All are obtained from the excellent "Winsock Programmer's FAQ", under Section 6.1 "Basic Example Programs":

    • "Basic Blocking Client"

      A client that uses blocking sockets. This is the simplest of the programs here


    • "Asynchronous I/O Client"

      A client that uses asynchronous sockets. This program is a GUI MFC program, but it does not use 'CAsyncSocket' or its derivatives.


    • "CAsyncSocket-based Client"

      A client that uses MFC's asynchronous sockets wrapper class: 'CAsyncSocket'


    • "Basic Blocking Server"

      A simple server that uses blocking sockets.


    • "Multithreaded Server"

      A server that sends each new connection off to its own thread to be handled while the main thread sits in a loop accepting connections.


    • "select()-based Server"

      A server that handles many connections using the 'select()' function to manage them all within a single thread.



    Last edited by Andreas Masur; July 25th, 2005 at 03:31 PM.
    Reply With Quote
    Reply

    Bookmarks
    Go Back   CodeGuru Forums > CodeGuru Technical FAQs > CodeGuru Individual FAQs


    Thread Tools Search this Thread
    Search this Thread:

    Advanced Search
    Display Modes

    Posting Rules
    You may not post new threads
    You may not post replies
    You may not post attachments
    You may not edit your posts

    BB code is On
    Smilies are On
    [IMG] code is On
    HTML code is On
    Forum Jump


    All times are GMT -5. The time now is 08:17 AM.



    Acceptable Use Policy


    The Network for Technology Professionals

    Search:

    About Internet.com

    Legal Notices, Licensing, Permissions, Privacy Policy.
    Advertise | Newsletters | E-mail Offers


    Powered by vBulletin® Version 3.7.3
    Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.