Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Send big packet - raspberrypi tcp socket  (Read 4132 times)

0 Members and 1 Guest are viewing this topic.

gus

  • Newbie
  • *
  • Posts: 6
    • View Profile
Send big packet - raspberrypi tcp socket
« on: September 27, 2015, 11:25:20 am »
Hi,

first, thanks for this awsome library  ;D

I have a problem while sending packet using SFML network tcp socket on raspberry pi. I'm basically sending a rather big packet (an uncompressed image), and while the programm works fine on windows (the image in recieved and sent perfectly), it doesn't work on the raspberry pi (the raspberry pi only send the image, it is received on another computer).
Or to be more precise, it doesn't work if the image is too big (ie the packet is too big). With a small image, things works. Besides, sending one "too big" packet seems to mess up every following packets, too big or not.

Here is the sending code
        packet << sf::Uint32(img.size().width);
        packet << sf::Uint32(img.size().height);
        for (int x = 0; x < img.size().width; x++)
        {
                for (int y = 0; y < img.size().height; y++)
                {
                        cv::Vec3b c = img.at<cv::Vec3b>(y, x);
                        packet << sf::Uint32((int)c.val[0]);
                        packet << sf::Uint32((int)c.val[1]);
                        packet << sf::Uint32((int)c.val[2]);
                }
        }

Any idea what might be happening? Oh and the sending socket is blocking and the reciever socket is non blocking.

Thanks!

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Send big packet - raspberrypi tcp socket
« Reply #1 on: September 27, 2015, 11:41:30 am »
How big is big and what does Wireshark tell you?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

gus

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Send big packet - raspberrypi tcp socket
« Reply #2 on: September 27, 2015, 11:44:15 am »
well the image is 360*480*sizeof(Uint32).
it works with (360/20)*(480/20)(Uint32) might work with something bigger though, I don't know the exact limit ;)

I don't know what Wireshark is, i'll look into it ;)



Gambit

  • Sr. Member
  • ****
  • Posts: 283
    • View Profile
Re: Send big packet - raspberrypi tcp socket
« Reply #3 on: September 27, 2015, 11:48:56 am »
Wireshark is basically a network packet viewer. I cant remember the exact name for it but it will allow you to view the packet traffic on a specific network device.

Just a side note about your code, you are casting c.val[N] to a signed int then using it in an unsigned int so be careful of narrowing conversions. In Visual Studio 2015 I dont believe such code will compile without an explicit static_cast. Also you might prefer static_cast over c-style casting since its a little more type/conversion-safe but thats purely personal preference.

gus

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Send big packet - raspberrypi tcp socket
« Reply #4 on: September 27, 2015, 01:10:53 pm »
mkay seems like I bricked my pi by installing wireshark. I have to wipe out everything/reinstall evezrything, might take some time :(

gus

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Send big packet - raspberrypi tcp socket
« Reply #5 on: September 27, 2015, 11:01:04 pm »
Ok I've found the problem: by default tcp sockets are in non blocking mode on the raspberry pi... I think this behavior should be changed or at least documented (I got the impression from the tutorials that it was on blocking by default at least) as it's different for different platforms.

binary1248

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1405
  • I am awesome.
    • View Profile
    • The server that really shouldn't be running
Re: Send big packet - raspberrypi tcp socket
« Reply #6 on: September 27, 2015, 11:54:45 pm »
What makes you think that sockets are non-blocking by default? SFML makes sure to explicitly set them as blocking when they are created regardless of which platform it is running on. Any behaviour other than that is a bug.

If you can provide a minimal code example that reproduces this bug, we can look into it ourselves.
SFGUI # SFNUL # GLS # Wyrm <- Why do I waste my time on such a useless project? Because I am awesome (first meaning).

gus

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Send big packet - raspberrypi tcp socket
« Reply #7 on: September 28, 2015, 09:47:05 am »
Wouuuups big mistake: while added a socket.setBlocking(false) in a strange place (some left over from old code) and didn't noticed it..

Anyway, thanks!  ;D