-
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.
-
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();
}
-
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();
}
-
How client can create object in server?
-
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++???
-
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.
-
Any sample reference code would help
-
How to create an object in the server and store client specific data? Using FIFO is it possible or any other method?