Thread: Windows C++ asynchronous

  1. #1
    Registered User
    Join Date
    Nov 2008
    Posts
    222

    Thumbs up Windows C++ asynchronous

    I am newbie to Windows C++ asynchronous client server application.
    I am trying to develop a client and server. Both must connect through FIFO and make sync async calls and send data.Both sync and async connect must be handled in server. Whatever data send by client must be stored by server. How to create a class with certain attributes which will be custom? Basically need to store custom objects. Please help me.

  2. #2
    Registered User
    Join Date
    Nov 2008
    Posts
    222
    Below is my server side code

    Code:
    #include <iostream>
    #include "SocketClient.h"
    #include "SocketServer.h"
    
    using namespace std;
    
    bool good=true;
    
    void messageReceived(messageStruct *s)
    {
        cout << "client: " << s->message << endl;
    }
    
    void errorOccurred(errorStruct *e)
    {
        cout << e->code << " : " << e->message << endl;
        good=false;
    }
    
    int main()
    {
        SocketServer server(5555);
        SocketClient client(server.accept());
        client.setErrorCallback(errorOccurred);
        client.setMessageCallback(messageReceived);
    
        while(good){};
    
        client.close();
        server.close();
    }

  3. #3
    Registered User
    Join Date
    Nov 2008
    Posts
    222
    Below is my client side code. I just created simple client server. Client connect to server and send messages.Server implement callback messages and displays it.
    Now I need to know how to do the following?

    1) Both must connect through FIFO and make sync async calls and send data
    2) How to create a class with certain attributes which will be custom? Basically need to store custom objects.


    Code:
    #include <iostream>
    #include <fstream>
    #include "SocketClient.h"
    
    using namespace std;
    
    void onError(errorStruct *e)
    {
        cout << e->message << endl;
    }
    
    int main()
    {
        SocketClient client("127.0.0.1", 5555);
        client.setErrorCallback(onError);
        client.connect();
    
        string str;
        while(1)
        {
            cout << ">";
            getline(cin, str);
            client.send(str);
        }
        
        /* NEW */               //  You can now send streams this way
        
        ifstream file("/path/to/file");
        client.send(file);      // The server will receive the STRING CONTENT of the file.
                                // But I'm working on a new version to receive the whole file directly (not as a string)
        /* NEW */
        
        client.close();
    }

  4. #4
    Registered User
    Join Date
    Nov 2008
    Posts
    222
    How client can create object in server?

  5. #5
    Registered User
    Join Date
    Nov 2008
    Posts
    222
    Client must be able to send some data to server via FIFO, in a structure and server must store the information. How can I do this in c++???

  6. #6
    Registered User
    Join Date
    Nov 2008
    Posts
    222
    Do I need to serialised the info coming from client to server?? If so any third party library can be used to do this or use normal win 32 functions?? Please suggest.

  7. #7
    Registered User
    Join Date
    Nov 2008
    Posts
    222
    Any sample reference code would help

  8. #8
    Registered User
    Join Date
    Nov 2008
    Posts
    222
    How to create an object in the server and store client specific data? Using FIFO is it possible or any other method?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Asynchronous programming
    By beatleman in forum C# Programming
    Replies: 3
    Last Post: 05-26-2015, 06:17 AM
  2. Asynchronous Serial I/O
    By bear820301 in forum Linux Programming
    Replies: 2
    Last Post: 10-14-2010, 12:12 AM
  3. Asynchronous Messaging
    By birkelbach in forum Networking/Device Communication
    Replies: 1
    Last Post: 05-30-2008, 02:35 PM
  4. Asynchronous sockets?
    By SyntaxBubble in forum Windows Programming
    Replies: 2
    Last Post: 02-04-2002, 09:33 PM

Tags for this Thread