dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: Client -Server implementation

  1. #1
    Join Date
    Mar 2008
    Posts
    20

    Client -Server implementation

    Hello All,

    I want to implement a Client -Server Application using VC++ (MFC).

    Could any one please guide me how do i proceed, any tutorials, sample codes to start with ? I came across winsock and trying to learn same for it.

    Thanks

    Abhi

  2. #2
    Join Date
    May 2008
    Posts
    8

    Re: Client -Server implementation

    hi!

    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:


    http://support.microsoft.com/kb/185728/EN-US/

    '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.


    http://support.microsoft.com/default...b;en-us;214396

    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).



    http://support.microsoft.com/kb/175668/EN-US/

    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.



    http://support.microsoft.com/kb/185728/EN-US/

    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



    http://msdn.microsoft.com/library/en...fc_chatter.asp

    '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.



    http://msdn.microsoft.com/library/en...c_chatsrvr.asp

    '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).


    http://www.microsoft.com/msj/archive/S25F.aspx

    '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 http://tangentsoft.net/wskfaq/, under Section 6.1 "http://tangentsoft.net/wskfaq/examples/basics/


    http://tangentsoft.net/wskfaq/exampl...ic-client.html

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



    http://tangentsoft.net/wskfaq/exampl...ent/index.html

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



    http://tangentsoft.net/wskfaq/exampl...ent/index.html

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



    http://tangentsoft.net/wskfaq/exampl...ic-server.html

    A simple server that uses blocking sockets.



    http://tangentsoft.net/wskfaq/exampl...ed-server.html

    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.



    http://tangentsoft.net/wskfaq/exampl...ct-server.html

    A server that handles many connections using the 'select()' function to manage them all within a single thread.
    Last edited by curiousGUY; May 6th, 2008 at 07:22 AM.

  3. #3
    Join Date
    May 2008
    Posts
    8

    Re: Client -Server implementation

    hi!

    i send u some very important links to implement client server in MFC.

    but on the other way i try my best last couple of days to implement UDP client server in win32 using vc++ to send and receive broadcast messages.

    do u have any source code for this.
    THX

  4. #4
    Join Date
    Mar 2008
    Posts
    20

    Re: Client -Server implementation

    Thanks a lot!!

    I am sorry about it but i am a beginner in VC++ and I do not have any code wht you have asked for :-(

    Could you please upload the some very important links to implement client server in MFC,here on forums, so its useful for all of us ?

    Many thanks!!

    Abhi

  5. #5
    Join Date
    Nov 2002
    Location
    California
    Posts
    4,556

    Re: Client -Server implementation

    Hey curiuosGuy, that's a cut-and-paste of a FAQ here at codeguru: "FAQ: Where can I find examples of socket programs?" at http://www.codeguru.com/forum/showthread.php?t=326666

    Next time, just post a link.

    Mike

  6. #6
    Join Date
    Nov 2002
    Location
    California
    Posts
    4,556

    Re: Client -Server implementation

    Leo,

    As a beginner, start with purely console-style applications. That way, you will not be distracted by user-interface issues:

    "Beej's Guide to Network Programming" from Beej at http://beej.us/guide/bgnet/ . This is a good guide for beginners. Beej's guide is written primarily for Linux/Unix, but it's easily adaptable to Winsock/other OSs, since it uses basic ideas from the original BSD socket implementation.

    FAQ: "Where can I find examples of socket programs?" at http://www.codeguru.com/forum/showthread.php?t=326666 . Remember to confine yourself to the select-based console-style samples

    "Winsock Programmer's FAQ", under Section 6.1 "Basic Example Programs": http://tangentsoft.net/wskfaq/examples/basics/


    If gaming is your ultimate goal, then also:

    "Multiplayer and Networking Tutorials" at http://www.gamedev.net/reference/list.asp?categoryid=30 . Some of these are better than others, so be choosy

    Mike

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)