C++Builder Programming Forum
C++Builder  |  Delphi  |  FireMonkey  |  C/C++  |  Free Pascal  |  Firebird
볼랜드포럼 BorlandForum
 경고! 게시물 작성자의 사전 허락없는 메일주소 추출행위 절대 금지
C++빌더 포럼
Q & A
FAQ
팁&트릭
강좌/문서
자료실
컴포넌트/라이브러리
메신저 프로젝트
볼랜드포럼 홈
헤드라인 뉴스
IT 뉴스
공지사항
자유게시판
해피 브레이크
공동 프로젝트
구인/구직
회원 장터
건의사항
운영진 게시판
회원 메뉴
북마크
볼랜드포럼 광고 모집

C++빌더 Q&A
C++Builder Programming Q&A
[5237] 이건 어떻게 스레드를 처리를 해야하는지? (고수님들 아실텐데)
시빌더사냥꾼 [] 2771 읽음    2001-02-06 23:49
안녕하세요..구동한 소스를 가지고 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

+ -

관련 글 리스트
5237 이건 어떻게 스레드를 처리를 해야하는지? (고수님들 아실텐데) 시빌더사냥꾼 2771 2001/02/06
5243     Re:이건 어떻게 스레드를 처리를 해야하는지? (고수님들 아실텐데) 박지훈.임프 2983 2001/02/07
5255         다시 올립니다. 한번 보시고용..조언좀..해주시면 감사르.(고수님들 아실텐데) 시빌더사냥꾼 2839 2001/02/07
Google
Copyright © 1999-2015, borlandforum.com. All right reserved.