1,317
社区成员
发帖
与我相关
我的任务
分享
void __fastcall TMainFrm::FormCreate(TObject *Sender)
{
TIniFile *ini;
ini=new TIniFile(".//SAS_Config.ini");
LedIp=ini->ReadString("infLED","LEDIP","192.168.224.250");
ini->WriteString("infLED","LEDIP",LedIp);
COMx=ini->ReadInteger("infLED","端口",2929);
ini->WriteInteger("infLED","端口",COMx);
LEDIpPort=COMx;
delete ini;
try
{
ClientSocket1->Active=false;
ClientSocket1->Address=LedIp;
//ClientSocket1->Host=LedIp;
ClientSocket1->Port=LEDIpPort;
//ClientSocket1->Open();
ClientSocket1->Active=true;
}
catch(...)
{
//
}
}
void sendbuf(unsigned char * buf,int bufIndex)
{
try
{
//ClientSocket1->Close();
//ClientSocket1->Active=false;
//ClientSocket1->Address=LedIp;
//ClientSocket1->Port=LEDIpPort;
//ClientSocket1->Open();
ClientSocket1->Active=true;
ClientSocket1->Socket->SendBuf(buf,bufIndex);
//ClientSocket1->Close();
}
catch(...)
{
//
}
}
void __fastcall TMainFrm::ClientSocket1Read(TObject *Sender, TCustomWinSocket *Socket)
{
///客户端读取信息
try
{
AnsiString Msg=Socket->ReceiveText();
unsigned char buf[100];
if(Msg.Length()<99)
{
strcpy(buf,Msg.c_str());
String ss="";
for(int i=0;i<Msg.Length();i++)
{
ss+=IntToHex(buf[i],2);
ss+=",";
}
InfoLedEdt->Text=ss;
}
///判断是不是自己发出的信息
// if(Msg!=Memo2->Lines->Strings[Memo2->Lines->Count-1])
// Memo2->Lines->Add(Msg);
}
catch(...)
{
//
}
}
void __fastcall TMainFrm::ClientSocket1Connect(TObject *Sender, TCustomWinSocket *Socket)
{
try
{
AnsiString Msg="连接成功-" + Socket->RemoteHost +"[地址]" + Socket->RemoteAddress + "[端口]" + IntToStr(Socket->RemotePort);
InfoLedEdt->Text=Msg;
}
catch(...)
{
//
}
}
void __fastcall TMainFrm::ClientSocket1Disconnect(TObject *Sender, TCustomWinSocket *Socket)
{
AnsiString Msg="信息显示屏连接断开..." ;
InfoLedEdt->Text=Msg;
}
unsigned char buf[2060]={0,0,0,0,0,0,0,0,0,0};
int bufIndex=1024,
ClientSocket1->Close();
ClientSocket1->Host="192.168.244.250";
ClientSocket1->Port=2929;
ClientSocket1->Open();
ClientSocket1->Active=true;
ClientSocket1->Socket->SendBuf(buf,bufIndex);
ClientSocket1->Close();