How to send compressed string through socket ?

  • Thread starter Thread starter fniles
  • Start date Start date
F

fniles

I need to compress strings, then send it through socket.
After I compress it (I use GZipStream, but I can use other compression
component, too), how can I send it through socket ?
I am using socketwrench .NET Component, and it can send either string
or byte array.
Thank you.

Imports System.IO
Imports System.IO.Compression

Dim sPacket As String
Dim buffer() As Byte
Dim totalCount As Integer
Dim mem As New IO.MemoryStream
Dim gz As New System.IO.Compression.GZipStream(mem,
IO.Compression.CompressionMode.Compress, True)
Dim encoding As New System.Text.UTF8Encoding()

buffer = encoding.GetBytes(sPacket)
gz.Write(buffer, 0, buffer.Length)
gz.Close()
Socket.Write(...) --> How can I send the compressed string or byte
array to Socket ?
 
Thank you for your quick reply.
Or are you having trouble figuring out how to create a socket?
No, I am having problem sending the compressed bytes through the
socket.

I tried buffer = mem.ToByteArray(), but it told me that "ToByteArray
is not a member of System.IO.MemoryStream".
mem is IO.MemoryStream.

Should I do this instead ?
buffer = mem.ToArray
 
It happens that fniles formulated :
Thank you for your quick reply.

No, I am having problem sending the compressed bytes through the
socket.

Well, bytes are bytes. That's why I was asking...
I tried buffer = mem.ToByteArray(), but it told me that "ToByteArray
is not a member of System.IO.MemoryStream".
mem is IO.MemoryStream.

Should I do this instead ?
buffer = mem.ToArray
Yes...sorry :)
 
Back
Top