powered by simpleCommunicator - 2.0.55     © 2025 Programmizd 02
Целевая тема:
Создать новую тему:
Автор:
Закрыть
Цитировать
Форумы / WinForms, .Net Framework [игнор отключен] [закрыт для гостей] / Named Pipe Server C# Named Pipe Client C++
2 сообщений из 2, страница 1 из 1
Named Pipe Server C# Named Pipe Client C++
    #38864141
ДАП
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Эх, не знаю, поможет мне здесь кто-то или нет, но на всякий случай спрошу. Если нет, то спрошу на другом форуме.

Есть Pipe сервер на C#
Код: c#
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
 NamedPipeServerStream sps = new NamedPipeServerStream("char", PipeDirection.InOut, 100);
            sps.WaitForConnection();
            Console.WriteLine("подключился клиент");

            using (StreamReader sr = new StreamReader(sps))
            {
                string temp;
                // We read a line from the pipe and print it together with the current time
                while ((temp = sr.ReadLine()) != null)
                {
                    Console.WriteLine("{0}: {1}", DateTime.Now, temp);
                }
            }

             Console.WriteLine("End");



Есть Pipe клиент на C++, который пытается отправить серверу строку
Код: plaintext
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
HANDLE hPipe; 
	LPTSTR lpvMessage=TEXT("Default message from client."); 
	TCHAR  chBuf[BUFSIZE]; 
	BOOL   fSuccess = FALSE; 
	DWORD  cbRead, cbToWrite, cbWritten, dwMode; 
	LPTSTR lpszPipename = TEXT("\\\\.\\pipe\\char"); 

	while (1) 
	{
		hPipe = CreateFile( 
         lpszPipename,   // pipe name 
         GENERIC_READ |  // read and write access 
         GENERIC_WRITE, 
         0,              // no sharing 
         NULL,           // default security attributes
         OPEN_EXISTING,  // opens existing pipe 
         0,              // default attributes 
         NULL);          // no template file 
 
		// Break if the pipe handle is valid. 
 
		if (hPipe != INVALID_HANDLE_VALUE) break; 
 
		// Exit if an error other than ERROR_PIPE_BUSY occurs. 
 
		if (GetLastError() != ERROR_PIPE_BUSY) 
		{
			MessageBox(NULL,TEXT("Could not open pipe. GLE=\n"+GetLastError()),TEXT(""),MB_OK);			
			return -1;
		}
 
		// All pipe instances are busy, so wait for 20 seconds. 
 
		if ( ! WaitNamedPipe(lpszPipename, 20000)) 
		{
			MessageBox(NULL,TEXT("Could not open pipe: 20 second wait timed out."),TEXT(""),MB_OK);
			return -1;
		} 
	} 

	cbToWrite = (lstrlen(lpvMessage)+1)*sizeof(TCHAR);

	fSuccess = WriteFile( 
      hPipe,                  // pipe handle 
      lpvMessage,             // message 
      cbToWrite,              // message length 
      &cbWritten,             // bytes written 
      NULL);                  // not overlapped 

	if ( ! fSuccess) 
	{
		MessageBox(NULL,TEXT("WriteFile to pipe failed. GLE=\n"+GetLastError()),TEXT(""),MB_OK);			
		return -1;
	}
	else
	{
		MessageBox(NULL,TEXT("OK"),TEXT(""),MB_OK);	
	}



Клиент на C++ успешно соединяется с сервером, успешно отправляет строку. Сервер на C# успешно принимает соединение от клиента, но строку принимать не хочет. Сервер просто висит и ожидает сообщения от клиента, ждёт, но ничего не происходит. При этом клиент куда-то же отправил строку...

Делал клиента на c#, отправлял строку - всё работает. А мне надо чтобы клиент был на c++ (из Win32 Dll).
Никто не видит в чём проблема ?
...
Рейтинг: 0 / 0
Named Pipe Server C# Named Pipe Client C++
    #38864169
ДАП
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Нашёл вроде ошибку.
ReadLine() - ожидал конца строки. Добавил к строке "\n" и сообщение пришло.
...
Рейтинг: 0 / 0
2 сообщений из 2, страница 1 из 1
Форумы / WinForms, .Net Framework [игнор отключен] [закрыт для гостей] / Named Pipe Server C# Named Pipe Client C++
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]