CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Aug 2001
    Location
    India
    Posts
    4

    Socket Programming

    Hi Friends,
    I'm new to socket programming.Can any one help me on how to use CSocket.
    thanking in advance
    Ramanand


  2. #2
    Join Date
    Jun 2001
    Posts
    126

    Re: Socket Programming

    Hello, I'm pretty much a beginner too. However, I've been using CSockets for several months now so maybe I can help.
    Are you creating a Client and a server or just one?
    In the simplest Client Server model, you must use 3 instances of CSocket. 2 of these CSockets are on the server side. The first on the server is a socket used for accepting calls, and should be created on a specific port (so clients know how to find it):
    CSocket sockAcptr.Create(iPort);
    sockAcptr.Listen();
    The sockAcptr listens for connection attempts, and will receive a message when it is able to accept a socket. When this happens, the sockAcptr should accept the call and attach it to the second server socket.
    sockAcptr.Accept(socksrvr);
    Now, all communication between the server and client goes through the socksrvr not the sockAcptr.
    The client socket is created on a default port, you dont have to specify:
    CSocket sockclient.Create();
    sockclient.Connect(sAddress, iPort);
    Connect to the server specifying the server IP address (can be in CString form) and the port the sockAcptr is listening on.
    To send information back and forth, I always use CSocketFiles with CArchives.
    Create a socketfile bound to the socket that will be sending (or receiving):
    CSocketFile file(pSock);
    Create an archive bound to the file either for sending or receiving:
    CArchive ar(&file, CArchive::store); OR CArchive ar(&file, CArchive::load);
    then you can use the archive to send and receive info;
    ar << sinfo;
    ar >> sinfo;
    Let me know if it helps or if you have anymore questions. you may want to double check MSDN to make sure i have the parameters in the right order on some methods.


  3. #3
    Join Date
    Jun 2003
    Location
    Bangalore,INDIA
    Posts
    122

    Re: Socket Programming

    Hello

    I am also in need of socket programming..i want to do a program which can communicate with two systems using their IP address. and i am new to this socket programming..Could you please help me in this regard..It would be appreciated if you can send any sample program..

    Thanks in advance.
    Poornima.

  4. #4
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652

    Re: Socket Programming

    [ Moved thread ]

  5. #5
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured