全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:1229
推到 Plurk!
推到 Facebook!

TServerSocket&自定封包格式

缺席
cashyy
高階會員


發表:117
回覆:322
積分:212
註冊:2004-04-30

發送簡訊給我
#1 引用回覆 回覆 發表時間:2005-06-21 23:55:44 IP:59.105.xxx.xxx 未訂閱
各位大大您好! 小弟目前試寫個網路程式,出現錯誤!不知是寫法有誤,還是觀念有誤? 程式碼如下:
  //server端!
  #include 
  #pragma hdrstop      #include "Unit1.h"
  struct test
  {
    int command;
    TMemoryStream *ms;
  };
  //---------------------------------------------------------------------------
  #pragma package(smart_init)
  #pragma resource "*.dfm"
  TForm1 *Form1;
  //---------------------------------------------------------------------------
  __fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
  {
  }
  //---------------------------------------------------------------------------
  void __fastcall TForm1::FormCreate(TObject *Sender)
  {
    ServerSocket1->Port = 9999;
    ServerSocket1->Active = true;        
  }
  //---------------------------------------------------------------------------
  void __fastcall TForm1::ServerSocket1ClientRead(TObject *Sender,
      TCustomWinSocket *Socket)
  {
    test com;
    Graphics::TBitmap *bit=new Graphics::TBitmap;
    Socket->ReceiveBuf(&com,sizeof(test));
    Edit1->Text = com.command;
    bit->LoadFromStream((TStream*)com.ms);
    Image1->Picture->Assign(bit);
  } 
  //---------------------------------------------------------------------------
  
  //client端!
  #include 
  #pragma hdrstop      #include "Unit1.h"
  /* Bmp轉成jpeg */
  #include "jpeg.hpp"
  struct test
  {
    int command;
    TMemoryStream *ms;
  };
  //---------------------------------------------------------------------------
  #pragma package(smart_init)
  #pragma resource "*.dfm"
  TForm1 *Form1;
  //---------------------------------------------------------------------------
  __fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
  {
  }
  //---------------------------------------------------------------------------
  void __fastcall TForm1::Button1Click(TObject *Sender)
  {
    ClientSocket1->Address = "127.0.0.1";
    ClientSocket1->Port = 9999;
    ClientSocket1->Active = true;
  }
  //---------------------------------------------------------------------------
  void __fastcall TForm1::Button2Click(TObject *Sender)
  {
    test aa;
    //創造一暫時圖檔
    Graphics::TBitmap *Bitmap=new Graphics::TBitmap;
    //設定暫時圖檔屬性
    Bitmap->Width = Screen->Width;
    Bitmap->Height = Screen->Height;
    Bitmap->PixelFormat = pf24bit;        //取得桌面DC handle
    HDC NewDC=::GetWindowDC(0);        //將全螢幕複製至Bitmap上
    ::BitBlt(Bitmap->Canvas->Handle,0,0,Screen->Width,Screen->Height,NewDC,0,0,SRCCOPY);        /* 取得滑鼠位置 */
    POINT pt;
    HCURSOR hCur=GetCursor();
    GetCursorPos(&pt);
    DrawIcon(Bitmap->Canvas->Handle, pt.x, pt.y, hCur);        /* 將BitBlt壓縮成jpeg */
    TJPEGImage *jpg=new TJPEGImage;
    jpg->Assign(Bitmap);
    jpg->CompressionQuality=70;
    jpg->Compress();
    jpg->SaveToStream((TStream*)aa.ms);
  
    aa.command = 1;
    ClientSocket1->Socket->SendBuf(&aa,sizeof(aa));        //釋放DC
    ReleaseDC(Form1->Handle,NewDC);
    //刪除Bitmap
    delete Bitmap;
    delete jpg;
  }
錯誤如下:
系統時間:2024-04-29 16:28:10
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!