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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Bernhard

Pages: [1]
1
Network / Custom Packet with Compression
« on: July 20, 2015, 06:02:44 pm »
Hi everyone,

I'm trying to use custom Packets with the TcpSocket class so that I can have automatic compression/decompression using Google's "Snappy" library. I'm having some difficulties with it though, and it seems that for some reason the "onReceive" function isn't firing on the receiver. Here is my custom packet:

class CustomPacket : public sf::Packet
{
        virtual const void* onSend(std::size_t& size)
        {
                const void* srcData = getData();
                std::size_t srcSize = getDataSize();
                // allocate space for compressed data
                size_t compressedLength = snappy_max_compressed_length(sizeof((const char*)srcData));
                char *compressed = new char[compressedLength];
                // compress the data
                snappy_status status = snappy_compress((const char*)srcData, srcSize, compressed, &size);
                return (const void*)compressed;
        }
        virtual void onReceive(const void* data, std::size_t size)
        {
                printf("Receiving...");
                size_t uncompressedLength;
                snappy_status status = snappy_uncompressed_length(
                        (const char*)data, size, &uncompressedLength);
                char *uncompressed = new char[uncompressedLength];
                std::size_t dstSize;
                status = snappy_uncompress(
                        (const char*)data, size, uncompressed, &dstSize);
                append((const void*)uncompressed, dstSize);
        }
};

On the sender, this is what I'm doing:

CustomPacket packet;
std::string s = "test message please ignore";
packet << s;
sf::Socket::Status status = socket.send(packet);

And on the receiver:

CustomPacket packet;
if (client.receive(packet) == sf::Socket::Done)
{
        std::string s;
        packet >> s;
        printf("Packet received: %s", s.c_str());
}

If I get rid of the compression algorithm in onSend, it works fine and prints out "Packet received: test message please ignore". With the compression in it though, as above, it prints out "Packet received: ", without any message.

Any ideas on why the custom packet isn't working properly?

2
Graphics / Re: Image compression for network transmission
« on: July 16, 2015, 08:06:09 pm »
Thanks. It's being transferred between computers on a gigabit LAN, so the bandwidth is substantial.

System Layout:
- 4 client computers, each one captures every rendered frame from an application running on them as a byte array (about 15hz each)
- 1 server, which needs to receive all of the frames from each of the 4 client computers and then do some image processing stuff with them

I know it's a strange setup, but it's a very strange and specific application where a change to the architecture is not possible. Some sort of video streaming solution with built-in compression/encoding would be nice, and have a stream from each client to the server. The server could then have a thread for each video stream it receives.

For each image frame, there's also some non-image metadata that needs to be sent with it.

3
Graphics / Image compression for network transmission
« on: July 16, 2015, 04:55:26 pm »
Hello,

I'm using SFML's Image class to hold some graphics data. It's in an uncompressed format, just raw bytes when I create an Image with it. I need to figure out a way to send a lot of these images quite rapidly over a network connection (I was thinking of using SFML's TcpSocket class). Is anyone familiar with any good tools for compression/encoding of images and ways to transport them in a smaller format over a network connection? I need to transmit about 50 images per second, each one is about 4MB uncompressed.

Thanks!

Pages: [1]