item2
Next»

contents

 

Introduction - 1

Background - 2

Deployment - 3

Starkits - 4

Tclkit - 5

Advanced topics - 6

Repositories - 7

Server apps - 8

Who uses this - 9

Examples - 10

Conclusion - 11

 

Acknowledgements

References

6.3 - Using Zlib for compression

The Zlib package is used by Tclkit to read compressed Starkits but it too is available to developers.

Given that the contents of a Starkit are already compressed, one common use for Zlib is to compress a client/server communications protocol by adding just a few lines of code.

For example, the server side of a client/server application might use something like the following to send data to the client:

    fconfigure -buffering full \
        -translation binary $client
    ...
    proc send_to_client {client txt} {
        set data [zlib compress $txt]
        set len [binary format s \
            [string length $data]]
        puts -nonewline $client "$len$data"
        flush $client
    }

Similarly, the client side would receive it using something like the following:

    fconfigure -buffering full \
        -translation binary $server
    ...
    proc receive_from_server {server} {
        binary scan [read $server 2] s len
        if {$len} {
            set data [read $server $len]
            set txt [zlib decompress $data]
        } else {
            set txt ""
        }
        return $txt
    }

see also

Starkit Home Page

Tclkit Home Page

Metakit Home Page

SDX Utility

Wikit Home Page

Tclers' Wiki

Author's Website

Papers & Presentations