OnClientRead Problem
BCB 5Am un device (RS232) care comunica cu serverul prin pachete dupa un anumit protocol.Am o aplicatie care citeste din COM port shi trimite serverului packet, dupa asta primeste raspuns de la server shi trimite yn COMPort. De fiecare data cynd din COM vin date, clientul deschide conexiunea catre server (altfel nu se poate, fiindca serverul ofera 11 sec de conexiune dupa asta o ynchide shi peste 5 secunde o deschide iar.).Trouble:Clientul nu citeste date din socket.Cod://---------------------------------------------------------------------------#include #pragma hdrstop#include "Unit1.h"#include "Loger_th.h"#include "Globalvars.h"//---------------------------------------------------------------------------#pragma package(smart_init)#pragma link "CPort"#pragma resource "*.dfm"TForm1 *Form1;//---------------------------------------------------------------------------__fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner){}//---------------------------------------------------------------------------void __fastcall TForm1::btnActivateClick(TObject *Sender){if(!ConnStat) { CS->Address=ebHost->Text; CS->Port=StrToInt(ebPort->Text); btnActivate->Caption="De-Activate"; }else btnActivate->Caption="Activate";//--------------------------------ebHost->Enabled=ConnStat;ebPort->Enabled=ConnStat;//--------------------------------try{ CP->Open(); AddMsg2Log(LOG_FILE,CP->Port+" successfully opened."); SBar->Panels->Items[1]->Text=" Opened."; } catch(EComPort &e) { SBar->Panels->Items[1]->Text=" Open Error."; AddMsg2Log(LOG_FILE,"Can not open "+CP->Port+"."); }}//---------------------------------------------------------------------------void __fastcall TForm1::CSConnect(TObject *Sender, TCustomWinSocket *Socket){ SBar->Panels->Items[3]->Text=" Connected.";}//---------------------------------------------------------------------------void __fastcall TForm1::CSConnecting(TObject *Sender, TCustomWinSocket *Socket){ SBar->Panels->Items[3]->Text=" Connecting..."; AddMsg2Log(LOG_FILE,"Clinet is trying to connect to "+CS->Address+":"+IntToStr(CS->Port)+" ...");}//---------------------------------------------------------------------------void __fastcall TForm1::CSDisconnect(TObject *Sender, TCustomWinSocket *Socket){ SBar->Panels->Items[3]->Text=" Disconnected."; AddMsg2Log(LOG_FILE,"Clinet disconnected from "+CS->Address+":"+IntToStr(CS->Port)); SStat=false;}//---------------------------------------------------------------------------void __fastcall TForm1::CSError(TObject *Sender, TCustomWinSocket *Socket, TErrorEvent ErrorEvent, int &ErrorCode){ SBar->Panels->Items[3]->Text=" Error."; AddMsg2Log(LOG_FILE,"An error occured durring connection of client to "+CS->Address+":"+IntToStr(CS->Port));}//---------------------------------------------------------------------------void __fastcall TForm1::CSRead(TObject *Sender, TCustomWinSocket *Socket){AnsiString a; a=Socket->ReceiveText(); AddMsg2Log(LOG_FILE,"Data successfully readed from socket."); CP->WriteStr(a); AddMsg2Log(LOG_FILE,"Data successfully writed to "+CP->Port);/* }catch(EComPort &e) { SBar->Panels->Items[3]->Text=" Data NOT readed."; AddMsg2Log(LOG_FILE,"Fail to read data from socket."); SBar->Panels->Items[1]->Text=" Data NOT writed."; AddMsg2Log(LOG_FILE,"Fail to write data to "+CP->Port); }*/}//---------------------------------------------------------------------------void __fastcall TForm1::CSWrite(TObject *Sender, TCustomWinSocket *Socket){ SBar->Panels->Items[3]->Text=" Writing data...";}//---------------------------------------------------------------------------void __fastcall TForm1::FormCreate(TObject *Sender){ConnStat=false;SStat=false;}//---------------------------------------------------------------------------void __fastcall TForm1::CPAfterClose(TObject *Sender){ SBar->Panels->Items[1]->Text=" Closed."; AddMsg2Log(LOG_FILE,CP->Port+" closed.");}//---------------------------------------------------------------------------void __fastcall TForm1::COMDPPacket(TObject *Sender, const AnsiString Str){if(!SStat){ try{ CS->Active=true; AddMsg2Log(LOG_FILE,"Connection etablished with "+CS->Address+":"+IntToStr(CS->Port)); SStat=true; } catch(ESocketError &e) { AddMsg2Log(LOG_FILE,"can not open Clinet connection to "+CS->Address+":"+IntToStr(CS->Port)); } }try{ if(CS->Active)CS->Socket->SendText(Str); AddMsg2Log(LOG_FILE,"Data successfuly sended to "+CS->Address+":"+IntToStr(CS->Port)); AddMsg2Log(LOG_FILE,Str); }catch(ESocketError &e) { AddMsg2Log(LOG_FILE,"Failed to send data to "+CS->Address+":"+IntToStr(CS->Port)); }}//---------------------------------------------------------------------------void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action){CP->Close();if(CS->Active)CS->Active=false;}//---------------------------------------------------------------------------не бойся делать то что никогда не делал, ибо ковчег построил любитель а ТИТАНИК - профессионалы.