Discussion:
windows c++ client server async FIFO
(too old to reply)
v***@gmail.com
2018-09-17 03:15:40 UTC
Permalink
Hi Team

I need to implement an interprocess communication in Windows, basic normal desktop application using C++. The client will connect to the server and will make different calls to it. They will communicate through a FIFO, the code doesn't have to be multi platform, the targeted platform is Windows. The client should be able to make synchronous and asynchronous calls to the server. The client should be able to send and receive different type of data to/from the server. The server needs to register a set of functions / classes for the client to use. The client needs to be able to create objects on the server and retrieve them, their attributes and call methods on them.

I am beginner to developing client server applications. I am just reading basics here and trying out few examples.
https://docs.microsoft.com/en-us/windows/desktop/ipc/named-pipes

Could you please provide me some inputs here?
JJ
2018-09-17 17:00:01 UTC
Permalink
Post by v***@gmail.com
Hi Team
I need to implement an interprocess communication in Windows, basic
normal desktop application using C++. The client will connect to the
server and will make different calls to it. They will communicate through
a FIFO, the code doesn't have to be multi platform, the targeted platform
is Windows. The client should be able to make synchronous and
asynchronous calls to the server. The client should be able to send and
receive different type of data to/from the server. The server needs to
register a set of functions / classes for the client to use. The client
needs to be able to create objects on the server and retrieve them, their
attributes and call methods on them.
I am beginner to developing client server applications. I am just reading
basics here and trying out few examples.
https://docs.microsoft.com/en-us/windows/desktop/ipc/named-pipes
Could you please provide me some inputs here?
IMO, the code examples on MSDN is pretty clear. Or, do you have anything you
don't yet understand?

If you're not familiar with asynchronous operation, I'd suggest you learn
what things are needed, and what things are affected when working with
asynchronous operation.
leo
2018-09-17 17:09:45 UTC
Permalink
Hi JJ

Thanks for your reply.

I have written sample code with just basic client server C++.



Now I have some confusion here. 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 serialize 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?? Also I don't have idea on how to do the below operations? Please suggest.



//Below is my server side 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



#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();

}
Post by JJ
Post by v***@gmail.com
Hi Team
I need to implement an interprocess communication in Windows, basic
normal desktop application using C++. The client will connect to the
server and will make different calls to it. They will communicate through
a FIFO, the code doesn't have to be multi platform, the targeted platform
is Windows. The client should be able to make synchronous and
asynchronous calls to the server. The client should be able to send and
receive different type of data to/from the server. The server needs to
register a set of functions / classes for the client to use. The client
needs to be able to create objects on the server and retrieve them, their
attributes and call methods on them.
I am beginner to developing client server applications. I am just reading
basics here and trying out few examples.
https://docs.microsoft.com/en-us/windows/desktop/ipc/named-pipes
Could you please provide me some inputs here?
IMO, the code examples on MSDN is pretty clear. Or, do you have anything you
don't yet understand?
If you're not familiar with asynchronous operation, I'd suggest you learn
what things are needed, and what things are affected when working with
asynchronous operation.
JJ
2018-09-18 14:06:23 UTC
Permalink
Post by leo
#include "SocketClient.h"
#include "SocketServer.h"
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)
Are those header files from below project?

https://github.com/OmarAflak/Asynchronous-Socket-Class-C-Windows

If so, then the one which is sent as a string is only the file size. The
file data is still sent as is (i.e. as binary), even though it was sent from
a char array.

In the server code, the file data is stored in a string variable, but the
data itself is still in its original form (i.e. as binary). The message
receiver callback in your application should treat the string contents as
binary data if you want to support receiving non-text data. The variable
type which contains the data itself is not really important, but as long as
the variable type can store binary data.

If you don't want to use string variable as the data container, store it in
a memory stream object, and pass it to the message receiver callback.
Loading...