C# TCP/IP 패킷 압축전송 DeflateStream질문 드립니다.

Internet03의 이미지

먼저 코드부터 보여드리겠습니다...

Server
byte[] sizebuf = new byte[sizeof(long)]; //받을 데이터 사이즈 크기 확인
screen_ns.Read(sizebuf, 0, sizeof(long));
screen_ns.Flush();

long size = BitConverter.ToInt64(sizebuf, 0);

if (size < 0 || size > 500000)
continue;
byte[] buf = new byte[size];
screen_ns.Read(buf, 0, buf.Length); //클라이언트로부터 값 리스브

MemoryStream ms = new MemoryStream(buf);

//ms.Write(buf, 0, buf.Length);

//ms.Position = 2;
MemoryStream ms2 = new MemoryStream();
using (DeflateStream ds = new DeflateStream(ms, CompressionMode.Decompress))
{
ds.CopyTo(ms2);
ds.Dispose();
te.Dispatcher.Invoke(new UpdataScreenDelegate(UpdataScreen), ms);
}

screen_ns.Flush();

Client
//화면얻어오기
System.Drawing.Rectangle rect = System.Windows.Forms.SystemInformation.VirtualScreen;
System.Drawing.Size size = new System.Drawing.Size(rect.Width, rect.Height);

System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(rect.Width, rect.Height);

System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bitmap);

g.CopyFromScreen(0, 0, 0, 0, size);

//얻어온 화면 메모리스트림에 쓰기
MemoryStream ms = new MemoryStream();
bitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);

ms.Seek(0, SeekOrigin.Begin);


MemoryStream ms2 = new MemoryStream();
DeflateStream ds = new DeflateStream(ms2, CompressionMode.Compress);//압축하기
ms.CopyTo(ds);

byte[] buf = new byte[ms.Length];

ms2.Seek(0, SeekOrigin.Begin);
ms2.Read(buf, 0, Convert.ToInt32(ms2.Length)); //buf에 쓰기
screenns.Write(BitConverter.GetBytes(ms2.Length), 0, sizeof(long)); //보낼 사이즈 전송

screenns.Flush();

Delay(80);
screenns.Write(buf, 0, buf.Length); //서버로 보내기
screenns.Flush();

-------------------------------------------------------------------------------------------------------------------

클라이언트는 자신의 컴퓨터 화면을 캡처하여 서버로 보내는 소스입니다.

그런데 DeflateStream으로 압축하여 보내서 서버로 받는것 까진 잘 됩니다.

문제는 서버에서 받은 이후

ds.CopyTo(ms2);

에서 "블록길이가 보수와 일치하지 않습니다.(block length does not match with its complement)" 오류가 발생합니다.

우선 구글링 결과 자바와 .Net의 통신인 경우 이런 오류가 인코딩때문에 발생 하여

ms.Position = 2;

2byte만 이동하여 압축을 해제하면 해결 된다는 글을 보아 혹시나 하여 사용 했지만...

"알 수 없는 블록 형식입니다. 스트림이 손상되었을 수 있습니다."

라는 오류가 뜨더군요.

전송 패킷을 압축하여 보내려고 했는데 이런 문제에 부딪힐 줄은 몰랐습니다.

어제 하루 종일 이것만 붙들고 있다가 도저희 혼자서는 해결을 할 수 없어서

도움을 요청해 봅니다.

감사합니다.

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.