|
안녕하세요..구동한 소스를 가지고 ID, PASS, EMAIL를 검색을 하면
프로그램 리소스가 30%가 됩니다. 음..메모리큐를 잡아 먹는 듯 한데...
이걸 Thread로 처리를 하려구 합니다. 세마포어, 뮤텍, 크리티컬섹션등의 Thread구현 방법에서
TThreadObject를 사용해서 하라는데 솔직히 잘 이해가 안됩니다. TScreen부분도 잘 이해가
안되구요...고수님들의 지도 바랍니다....
단순히 Thread를 Execute를 시키는 것이 아니라 서버측이여서 좀더 네트웍으로 생각을
해야할것 같거든요..그래서 앞이 캄캄합니다..흑흑..
//--------------------------------------------------------
Unit.cpp
//---------------------------------------------------------------------------
#include <vcl.h>
#include <winsock.h>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TLoginform *Loginform;
SOCKET GlobalSocket;
//---------------------------------------------------------------------------
__fastcall TLoginform::TLoginform(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TLoginform::LoginButtonClick(TObject *Sender)
{
String str = "login|" +
Edit1->Text +
"|" +
Edit2->Text +
"|";
ClientSocket1->Socket->SendText(str);
Edit2->Text = "";
}
//---------------------------------------------------------------------------
void __fastcall TLoginform::ClientSocket1Error(TObject *Sender,
TCustomWinSocket *Socket, TErrorEvent ErrorEvent, int &ErrorCode)
{
ErrorCode=0; //서버 연결 실패로 단정
StatusBar1->Panels->Items[0]->Text = "Error 발생 하였습니다.";
ClientSocket1->Socket->Close();
ClientSocket1->Active = false;
Edit1->Text = "";
Edit2->Text = "";
}
//---------------------------------------------------------------------------
void __fastcall TLoginform::Button3Click(TObject *Sender)
{
//설정을 먼저 하기 전에 클라이언트 활성화 를 죽인다.
if(ClientSocket1->Active)
{
ClientSocket1->Active = false;
}
if(InputQuery("연결을 설정 하십시요.","주소(IP) : ",Server))
{
if(Server.Length() > 0)
{
ClientSocket1->Address = Server;
ClientSocket1->Active = true;
}
}
StatusBar1->Panels->Items[0]->Text = ClientSocket1->
Address +
" 로 연결중 되었습니다.";
}
//---------------------------------------------------------------------------
void __fastcall TLoginform::ClientSocket1Disconnect(TObject *Sender,
TCustomWinSocket *Socket)
{
StatusBar1->Panels->Items[0]->Text = "서버와 연결이 끊어 졌습니다.";
}
//---------------------------------------------------------------------------
void __fastcall TLoginform::Button2Click(TObject *Sender)
{
ClientSocket1->Active = false;
ClientSocket1->Active = true;;
StatusBar1->Panels->Items[0]->Text = ClientSocket1->
Address +
" 로 연결중..";
}
//---------------------------------------------------------------------------
enidif
//---------------------------------------------------------------------------
Unit.h
//---------------------------------------------------------------------------
#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <ScktComp.hpp>
#include <ComCtrls.hpp>
//---------------------------------------------------------------------------
class TLoginform : public TForm
{
__published: // IDE-managed Components
TEdit *Edit1;
TEdit *Edit2;
TButton *LoginButton;
TClientSocket *ClientSocket1;
TButton *Button1;
TLabel *Label1;
TLabel *Label2;
TStatusBar *StatusBar1;
TButton *Button2;
TButton *Button3;
void __fastcall LoginButtonClick(TObject *Sender);
void __fastcall ClientSocket1Error(TObject *Sender,
TCustomWinSocket *Socket, TErrorEvent ErrorEvent,
int &ErrorCode);
void __fastcall Button3Click(TObject *Sender);
void __fastcall ClientSocket1Disconnect(TObject *Sender,
TCustomWinSocket *Socket);
void __fastcall Button2Click(TObject *Sender);
private: // User declarations
public: // User declarations
String Server; //IP Address
__fastcall TLoginform(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TLoginform *Loginform;
//---------------------------------------------------------------------------
#endif
|