StreamingSocket not sending until is closed


#1

Hello,
i’m trying to setup a StreamingSocket. Right now, it only works on windows (i created another topic for the OSX not working part).

I can create the StreamingSocket and connect to a remote server.
Then when i use the write function, nothing happens server side, but when i close my app, everything i tried to send is sent at once.
Right now my code is opening and closing the socket each time i want to send a message, which is really not a good practice, but the only examples i found using StreamingSocket to send data are one-shot demo of opening-writing-closing the socket right away.
I notice that most of the socket libraries have a “flush” function to force the pipe to send the data in the buffer, but there is nothing like that in Juce.

Is there something i’m missing ?

Here’s my code :

if (!sender.isConnected()) setupSender();

DBG(“Send TCP String :” << s << " > " << s.length());

sender.write(s.getCharPointer(), s.length());
sender.close();


#2

This is strange as we are setting the TCP_NODELAY flag on juce_Socket.cpp:94. Can you set a breakpoint at that line and see if this is actually executed on your computer? Maybe one of the previous setOption calls are failing.


#3

So with my actual code, which is closing the connection right after writing the packet, the breakpoint on line 94 is never triggered, but the options seem all good, and the command is sent to VLC.

The DBG result on the code below is “1 / 1 / 0 / 1”

DBG((int)setOption(handle, SO_RCVBUF, (int)65536) << "/" << (int)setOption(handle, SO_SNDBUF, (int)65536) << "/" << (int)isDatagram << "/" << (int)setOption(handle, IPPROTO_TCP, TCP_NODELAY, (int)1));

    return handle > 0
            && setOption (handle, SO_RCVBUF, (int) 65536)
            && setOption (handle, SO_SNDBUF, (int) 65536)
            && (isDatagram ? ((! allowBroadcast) || setOption (handle, SO_BROADCAST, (int) 1))
                            : setOption (handle, IPPROTO_TCP, TCP_NODELAY, (int) 1));

Then i removed the closing of the connection after the write method, here is what happen :
When i create the socket with this line :

sender.connect(useLocal->boolValue() ? "127.0.0.1" : remoteHost->stringValue(), remotePort->intValue()); 

the resetSocketOptions method is called with the same [good] result “1 / 1 / 0 / 1”

Then when i send the packet, nothing happens, i guess this is normal that the resetSocketOptions is not called anymore since i’m not closing and reconnecting at each write but still, the packet seems that it is not sent


#4

If you’ve got the motivation, you can check the code here :

This code is with the connection close at each write for now