Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

StreamSocket hangs when using SocketStream without calling shutdownSend #2384

Closed
KevDi opened this issue Jul 9, 2018 · 4 comments
Closed
Labels

Comments

@KevDi
Copy link
Contributor

KevDi commented Jul 9, 2018

Expected behavior

I want to use the StreamSocket with an SocketStream to send different Messages to a Server and get the Answers.

Actual behavior

If i use the Code shown under Steps to reproduce the problem the program hangs on the copyStream Function. Inside that it hangs on the read function from the InputStream. The Code only works if i call socket.shutdownSend(). If I call that before the copyStream Function is called everything works. But I couldn't use the Socket again to send another Message to the Server.
Is there a way to use the StreamSocket without calling shutdownSend on the Socket?

Steps to reproduce the problem

(please make this a SSCCE, if applicable and reasonable)

Poco::Net::SocketAddress socketAddress{ "10.50.1.89", 8888 };
Poco::Net::StreamSocket socket{ socketAddress };
Poco::Net::SocketStream str(socket);

str.write << "Message1";
str.flush();
std::stringstream ss;
Poco::StreamCopier::copyStream(str, ss);

This causes the Programm to hang on the copyStream Function call.

Poco::Net::SocketAddress socketAddress{ "10.50.1.89", 8888 };
Poco::Net::StreamSocket socket{ socketAddress };
Poco::Net::SocketStream str(socket);

str.write << "Message1";
str.flush();
socket.shutdownSend();
std::stringstream ss;
Poco::StreamCopier::copyStream(str, ss);

This Version gets me the Answer of the Server but i could not reuse the socket to send another Message because I had to close the Sending Part of it.

POCO version

1.9.0

Compiler and version

Visual Studio 2017

Operating system and version

Windows 10

Other relevant information

@roccocorsi
Copy link
Contributor

Thank you. You helped me with hanging StreamCopier I was facing. I was doing something less demanding, interacting with HTTP server, so send the request and get the response is all I need, so shutdownSend() solves my issue.

Seems for your case SocketStream is probably not the right thing to use. Sorry I have no real help except that there is a stackoverflow posting that suggests using DialogSocket class.

https://stackoverflow.com/questions/15540448/poconet-library-hangs-on-output-of-poconetsocketstream/25280624

@bridgewaterrobbie
Copy link

I have also encountered this issue. A note in the header might be a decent intermediary step.

@github-actions
Copy link

This issue is stale because it has been open for 365 days with no activity.

@github-actions github-actions bot added the stale label Jun 27, 2022
@aleks-f aleks-f closed this as not planned Won't fix, can't repro, duplicate, stale Jun 27, 2022
@davidcallen
Copy link

I have also encountered this issue when trying to send the contents of a file on the socket.
I tried the workaround of adding a shutdownSend() before the call to copyStream(). It now only sends 1025 bytes in the copyStream, but I have much more to send (50k to 100k). Without the workaround it would usually miss the last part of the file contents.
My code is like this :
std::streamsize SocketUtils::sendFile(Poco::Net::StreamSocket& streamSocket, const std::string& fileNamePath) { Poco::Net::SocketStream ostr(streamSocket); Poco::FileInputStream istr(fileNamePath, std::ios::binary); return bytesCopied = Poco::StreamCopier::copyStreamUnbuffered(istr, ostr); }
Note I get the issue using copyStreamUnbuffered() and copyStream().
Any help greatly appreciated. This issue has been driving my nuts for days.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants