all i have a QT app that opens a IPC port on windows and waits for a connection from a client... when i connect with QT client its fine, however a native windows app, it fails to get the proper data. I am convinced its a character encoding issue. But im unsure as to the *best* way to address it... i can alter either the QT app or the Native windows app..This will only run on windows, so portability isnt a concern. The Client MUST be native windows, so i cant do all QT... (i wish believe me)

I see the count of the data received in the client as "READ(30)", so i know data is going...

QT IPC Socket Code
Qt Code:
  1. void LocalSocketIpcServer::returnPrinter(QString printer)
  2. {
  3.  
  4. PRN_DEBUG() << "Returning: " << printer;
  5.  
  6. QByteArray block;
  7. QDataStream out(&block, QIODevice::ReadWrite);
  8. out.setVersion(QDataStream::Qt_4_0);
  9. out << (quint16)0;
  10. out << printer;
  11. out.device()->seek(0);
  12. out << (quint16)(block.size() - sizeof(quint16));
  13.  
  14. QLocalSocket *clientConnection = m_server->nextPendingConnection();
  15.  
  16. connect(clientConnection, SIGNAL(disconnected()),
  17. clientConnection, SLOT(deleteLater()));
  18.  
  19. clientConnection->write(block);
  20. clientConnection->flush();
  21. clientConnection->disconnectFromServer();
  22.  
  23. emit finishedSending();
  24. }
To copy to clipboard, switch view to plain text mode 


Native Windows client
Qt Code:
  1. #include <windows.h>
  2. #include <conio.h>
  3. #include <iostream>
  4. using namespace std;
  5.  
  6. const wchar_t cszPipeName[] = L"\\\\.\\pipe\\TestPort";
  7.  
  8. int main(int argc, wchar_t* argv[])
  9. {
  10. HANDLE hPipe = INVALID_HANDLE_VALUE;
  11.  
  12. do {
  13.  
  14. // Get handle to a read only pipe that must exists.
  15. hPipe = CreateFileW(
  16. cszPipeName,
  17. GENERIC_READ, // | GENERIC_WRITE,
  18. 0,
  19. NULL,
  20. OPEN_EXISTING,
  21. 0,
  22. NULL
  23. );
  24.  
  25. if( hPipe == INVALID_HANDLE_VALUE ){
  26. cerr << "CreateFile fail. Err: " << GetLastError() << endl;
  27. break;
  28. }
  29.  
  30. cout << "Press any key to exit" << endl;
  31.  
  32. wchar_t szMessage[256] = {0};
  33.  
  34. // Keep buffer null terminated. Don't use last element.
  35. DWORD dwMsgSize = (sizeof(szMessage)-1)*sizeof(wchar_t);
  36.  
  37. //while(!_kbhit()) {
  38.  
  39. // Read messages until an error on the pipe happen
  40. // or the user press any key on the keyboard.
  41. DWORD dwRead = 0;
  42. BOOL bRet = ReadFile(
  43. hPipe,
  44. szMessage,
  45. dwMsgSize,
  46. &dwRead,
  47. NULL
  48. );
  49. if(!bRet) {
  50.  
  51. cerr << "Read fail. Err: " << GetLastError() << endl;
  52. break;
  53. }
  54.  
  55. wcout << "READ (" << dwRead << ") " << szMessage << endl;
  56.  
  57. //} // end while
  58.  
  59. } while(false); // end do
  60.  
  61. if(hPipe != INVALID_HANDLE_VALUE) {
  62. CloseHandle(hPipe);
  63. }
  64.  
  65. return 0;
  66. }
To copy to clipboard, switch view to plain text mode