Forum Replies Created

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • basant_tomar
    Participant
    Post count: 2

    Please can someone help me out with this

    basant_tomar
    Participant
    Post count: 2

    hey Team,

    I am trying to decompress a compressed stream using XceedCompressedStream.Decompress
    but this keeps on showing an error regarding either end of stream or checksum error
    PLease help me out with this. I really need a solution
    here is my code

    for server :
    using Xceed.Compression;
    using Xceed.Compression.Formats;
    using System;
    using System.IO;
    using System.Net;
    using System.Net.Sockets;
    using System.Text;
    using System.Configuration;
    using XceedZipLib;

    namespace FileSystemDocumentationExamples.CompressionComponent
    {
    public class DecompressXceedCompressedStreamExample
    {
    private static void printHex(string Header, byte[] buffer)
    {
    StringBuilder hex = new StringBuilder(buffer.Length * 2);
    foreach (byte b in buffer)
    {
    hex.AppendFormat(“{0:x2} “, b);
    }
    Console.WriteLine(“** ” + Header + ” **”);
    Console.WriteLine(hex);
    }

    public static void Main(string[] args)
    {

    //StreamWriter writer = new StreamWriter(“D:\\Exception\\new.txt”);
    //Console.SetOut(writer);
    Xceed.Zip.ReaderWriter.Licenser.LicenseKey =”ZRT61-24AWA-8UKJY-ZBUA”;
    Xceed.Compression.Formats.Licenser.LicenseKey =”ZIN61-X4A1A-HUKEY-8BBA”;

    IPAddress ipAd = IPAddress.Parse(“127.0.0.1″);
    TcpListener serverSocket = new TcpListener(ipAd, 8001);
    TcpClient clientSocket = default(TcpClient);
    serverSocket.Start();

    Console.WriteLine(” >> Server Started”);

    clientSocket = serverSocket.AcceptTcpClient();

    Console.WriteLine(” >> Accept connection from client”);

    NetworkStream networkStream = clientSocket.GetStream();
    MemoryStream ms=new MemoryStream();
    byte[] bytesFrom = new byte[78];
    int bytesread = 0;

    try
    {
    if (networkStream.CanRead)
    {

    bytesread = networkStream.Read(bytesFrom, 0, bytesFrom.Length);
    printHex(“Hex Before “,bytesFrom);
    Console.WriteLine(“Bytes read : ” + bytesread);
    File.WriteAllBytes(@”D:\Exception\MCX.Bin”, bytesFrom);
    //networkStream.Flush();
    }
    }
    catch (Exception ex)
    {
    Console.WriteLine(ex.ToString());
    System.IO.File.WriteAllText(@”D:\Exception\exceptions.txt”, ex.ToString());

    }
    byte[] uncompressedData = new Byte[78];
    byte[] buffer = new byte[80];
    int bRead = bytesread;

    buffer = bytesFrom;
    int k = 0;

    try
    {
    uncompressedData = XceedCompressedStream.Decompress(buffer, 0, 78);
    }
    catch (Exception E)
    {
    Console.WriteLine(E.Message);
    }

    k = uncompressedData.Length;

    Console.WriteLine(“total number of bytes readed” + k);
    networkStream.Write(uncompressedData, 0, bRead);

    clientSocket.Close();
    serverSocket.Stop();
    Console.ReadLine();

    }

    }
    }

    for client :

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Net.Sockets;
    using System.IO;

    namespace sendingBinfiledata
    {
    class Program
    {
    static void Main(string[] args)
    {
    System.Net.Sockets.TcpClient clientSocket = new System.Net.Sockets.TcpClient();
    using (TcpClient tcpClient = new TcpClient(“127.0.0.1″, 8001))
    {
    using (NetworkStream networkStream = tcpClient.GetStream())
    {
    FileStream fs = new FileStream(@”D:\mi.txt”, FileMode.Open, FileAccess.Read);
    byte[] dataToSend = new byte[fs.Length];
    int k= fs.Read(dataToSend, 0, System.Convert.ToInt32(fs.Length));

    Console.WriteLine(“byte sent” + k);
    //byte[] dataToSend = File.ReadAllBytes(@”D:\mi.txt”);

    //byte[] dataToSend = {0x00,0x33,0x30,0x30,0x32,0x31,0x0e,0x2c,0x64,0x8d,0xb0,0xab,0x64,0x00,0x83,0xcf,0x0c,0x3c,0x0c,0x0c,0x51,0x1a,0xcc,0x0c,0x7e,0x4c,0x0c,0x43,0x0e,0x5c,0x6a,0xe2,0x22,0x52,0x25,0x00,0x02,0x06,0x2b,0x83};

    networkStream.Write(dataToSend,0,dataToSend.Length);

    StringBuilder hex = new StringBuilder(dataToSend.Length * 2);
    foreach (byte b in dataToSend)
    hex.AppendFormat(“{0:x2}”,b);

    Console.WriteLine(hex);

    networkStream.Flush();

    byte[] inStream = new byte[1024];
    Console.WriteLine(“decompressed data”);

    networkStream.Read(inStream, 0, inStream.Length);
    string line = Encoding.UTF8.GetString(inStream);
    System.IO.File.WriteAllText(@”D:\Myzip\JAI.txt”, line);
    Console.WriteLine(line);
    Console.ReadLine();
    }
    }

    }
    }
    }

Viewing 2 posts - 1 through 2 (of 2 total)