Click here to Skip to main content
15,887,027 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: DIALOG WITH MULTIPLE THREADS Pin
Victor Nijegorodov25-Jun-18 8:52
Victor Nijegorodov25-Jun-18 8:52 
QuestionCan't automate Excel from Windows 10 Pin
garyflet21-Jun-18 8:39
garyflet21-Jun-18 8:39 
AnswerRe: Can't automate Excel from Windows 10 Pin
Victor Nijegorodov21-Jun-18 20:59
Victor Nijegorodov21-Jun-18 20:59 
AnswerRe: Can't automate Excel from Windows 10 Pin
_Flaviu21-Jun-18 22:43
_Flaviu21-Jun-18 22:43 
Questionlooking for 3rd party library to "create overlay guided user experiences" ? Pin
Maximilien21-Jun-18 8:17
Maximilien21-Jun-18 8:17 
QuestionTCP/IP Socket connectivity issue in Internet Pin
manoharbalu19-Jun-18 1:44
manoharbalu19-Jun-18 1:44 
AnswerRe: TCP/IP Socket connectivity issue in Internet Pin
Jochen Arndt19-Jun-18 2:52
professionalJochen Arndt19-Jun-18 2:52 
GeneralRe: TCP/IP Socket connectivity issue in Internet Pin
manoharbalu19-Jun-18 3:44
manoharbalu19-Jun-18 3:44 
I have copied the Server code and Client code below. As of now, both the functions send (Server side) and Receive code (client code) are timer driven with frequency of 1 second. Can you please detail me this step which you had mentioned as "Check all function return codes and check for timeouts (detect dropped connections)." as I am unable to understand that clearly.

This function call in the below code in Server "tFrm->UpdateOprs(&tData);" sends the data to all the connected clients (In my case, I have connected only one Client). This function call ("tFrm->UpdateOprs(&tData);") to send data is called 5 times in a Send cycle and correspondingly 5 calls to receive data in the client side is called.

//Server Side Code
void SendActiveData()
{
POSITION pos;
long int Offset;
CString tString;
CTagBase* OTemp;
int i;

CTrans tData;
CTrans cData[50];

CMainFrame* tFrm = (CMainFrame*)AfxGetMainWnd();
tFrm->tId = 0;

if(bBackTrkTime)
{
bBackTrkTime = false;
tData.Init();
for(i=0;i<livedatacount.count;i++)
tdata.m_sdata.insert(i,livearray[i]);

="" tfrm-="">UpdateOprs(&tData);
LiveArray[0] = Esim->HOLD;
return;
}

if(bModelChange)
{
bModelChange = false;
tData.Init();
for(i=0;i<livedatacount.count;i++)
tdata.m_sdata.insert(i,livearray[i]);
="" tfrm-="">UpdateOprs(&tData);
LiveArray[0] = Esim->HOLD;
return;

}

if(!bMesgToOpr)
LiveArray[0]=Esim->HOLD;
else
{
bMesgToOpr = FALSE;
tData.Init();
for(i=0;i<livedatacount.count;i++)
tdata.m_sdata.insert(i,livearray[i]);
="" tfrm-="">UpdateOprs(&tData);
return;
}

Offset = 1;
pos = OLivePointList.GetHeadPosition();

if(OPSTATION == CENTUMXL || OPSTATION == CS3000|| OPSTATION == FOXBORO || OPSTATION == CENTUMVP || OPSTATION == EXPERION || OPSTATION == ABB || OPSTATION == DELTAV
|| OPSTATION == SIEMENS || OPSTATION == TDC3000)
{
for(i=0;i<controllercount;i++)
{
="" otemp="(CTagBase*" )="" olivepointlist.getat(pos);
="" cstring="" str="OTemp-">GetTagName();
unsigned char* Temp = OTemp->SendLivePoints();
long lTemp = Offset+(i*LIVECONSIZE);
for(int j = 0; j < LIVECONSIZE; j++)
{
LiveArray[lTemp] = Temp[j];
lTemp++;
}
OLivePointList.GetNext(pos);
}
Offset += (ControllerCount*LIVECONSIZE);
for(i=0;i<indicatorcount;i++)
{
="" otemp="(CTagBase*" )="" olivepointlist.getat(pos);

="" unsigned="" char*="" temp="OTemp-">SendLivePoints();
long lTemp = Offset + (i * LIVEINDSIZE);
for(int j = 0; j < LIVEINDSIZE; j++)
{
LiveArray[lTemp] = Temp[j];
lTemp++;
}
OLivePointList.GetNext(pos);
}
Offset += IndicatorCount*LIVEINDSIZE;
for(i=0;i<switchcount;i++)
{
=""
="" otemp="(CTagBase*" )="" olivepointlist.getat(pos);
="" unsigned="" char*="" tem="OTemp-">SendLivePoints();
long lTemp = Offset + (i * LIVESWTSIZE);
for(int j = 0; j < LIVESWTSIZE; j++)
{
LiveArray[lTemp] = Tem[j];
lTemp++;
}
OLivePointList.GetNext(pos);
}
Offset += SwitchCount*LIVESWTSIZE;
for(i=0;i<eswitchcount;i++)
{
="" unsigned="" char="" tswitch[2]="{0};
" otemp="(CTagBase*" )="" olivepointlist.getat(pos);
="" tswitch[0]="*(OTemp-">SendLivePoints());
long TmpOffset = Offset + (i * LIVESWTSIZE);

Tswitch[0] = *(OTemp->SendLivePoints());
(LiveArray[TmpOffset]) = Tswitch[0];
OLivePointList.GetNext(pos);

}
Offset += ESwitchCount*LIVESWTSIZE;
for(i=0;i<globecount;i++)
{
="" otemp="(CTagBase*" )="" olivepointlist.getat(pos);
="" unsigned="" char="" *ggg,="" gg[4];
="" ggg="(unsigned" char*="" )otemp-="">SendLivePoints();
GG[0]=GGG[0];
GG[1]=GGG[1];
GG[2]=GGG[2];
GG[3]=GGG[3];
memmove((void* )((LiveArray+Offset)+(i*LIVEGLBSIZE)),GG,4);
OLivePointList.GetNext(pos);
}
Offset += GlobeCount*LIVEGLBSIZE;

long TmpOffset;

for(i=0;i<alarmcount;i++)
{
="" otemp="(CTagBase*" )="" olivepointlist.getat(pos);
="" tmpoffset="Offset+(i*LIVEALMLITSIZE);
" unsigned="" char="" *palarm="OTemp-">SendLivePoints();
LiveArray[TmpOffset] = pAlarm[0];
OLivePointList.GetNext(pos);
}
Offset += AlarmCount*LIVEALMLITSIZE;

for(i=0;i<lightcount;i++)
{
="" otemp="(CTagBase*" )="" olivepointlist.getat(pos);
="" long="" tmpoffset="Offset+(i*LIVEALMLITSIZE);
" unsigned="" char="" *plight="OTemp-">SendLivePoints();
LiveArray[TmpOffset] = pLight[0];
OLivePointList.GetNext(pos);
}
Offset += LightCount*LIVEALMLITSIZE;
for(i=0;i<amscount;i++)
{
="" otemp="(CTagBase*" )="" olivepointlist.getat(pos);
="" long="" tmpoffset="Offset+(i*LIVEAMSSIZE);
" unsigned="" char="" *pams="OTemp-">SendLivePoints();
for(int j = 0; j < LIVEAMSSIZE; j++)
{
LiveArray[TmpOffset] = pAms[j];
TmpOffset++;
}
OLivePointList.GetNext(pos);
}
Offset += AmsCount*LIVEAMSSIZE;
}
if(OPSTATION == HONEYWELL)
{
for(i=0;i<controllercount;i++)
{
="" otemp="(CTagBase*" )="" olivepointlist.getat(pos);
="" unsigned="" char*="" temp="OTemp-">SendLivePoints();
long lTemp = Offset+(i*LIVECONSIZE);
for(int j = 0; j < LIVECONSIZE; j++)
{
LiveArray[lTemp] = Temp[j];
lTemp++;
}
OLivePointList.GetNext(pos);
}

Offset += (ControllerCount*LIVECONSIZE);
for(i=0;i<indicatorcount;i++)
{
="" otemp="(CTagBase*" )="" olivepointlist.getat(pos);
="" unsigned="" char*="" temp="OTemp-">SendLivePoints();
long lTemp = Offset + (i * LIVEINDSIZE);
for(int j = 0; j < LIVEINDSIZE; j++)
{
LiveArray[lTemp] = Temp[j];
lTemp++;
}
OLivePointList.GetNext(pos);
}
Offset += IndicatorCount*LIVEINDSIZE;

for(i=0;i<switchcount;i++)
{
="" otemp="(CTagBase*" )="" olivepointlist.getat(pos);

="" unsigned="" char*="" tem="OTemp-">SendLivePoints();
long lTemp = Offset + (i * LIVESWTSIZE);
for(int j = 0; j < LIVESWTSIZE; j++)
{
LiveArray[lTemp] = Tem[j];
lTemp++;
}
OLivePointList.GetNext(pos);
}
Offset += SwitchCount*LIVESWTSIZE;

for(i=0;i<eswitchcount;i++)
{
="" unsigned="" char="" tswitch[2]="{0};
" otemp="(CTagBase*" )="" olivepointlist.getat(pos);
="" tswitch[0]="*(OTemp-">SendLivePoints());
long TmpOffset = Offset + (i * LIVESWTSIZE);

Tswitch[0] = *(OTemp->SendLivePoints());
(LiveArray[TmpOffset]) = Tswitch[0];
OLivePointList.GetNext(pos);

}
Offset += ESwitchCount*LIVESWTSIZE;

for(i=0;i<globecount;i++)
{
="" otemp="(CTagBase*" )="" olivepointlist.getat(pos);
="" unsigned="" char*="" temp="OTemp-">SendLivePoints();
long lTemp = Offset + (i * LIVEGLBSIZE);
for(int j = 0; j < LIVEGLBSIZE; j++)
{
LiveArray[lTemp] = Temp[j];
lTemp++;
}
OLivePointList.GetNext(pos);
}
Offset += GlobeCount*LIVEGLBSIZE;

long TmpOffset;
for(i=0;i<alarmcount;i++)
{
="" otemp="(CTagBase*" )="" olivepointlist.getat(pos);
="" tmpoffset="Offset+(i*LIVEALMLITSIZE);
" unsigned="" char="" *palarm="OTemp-">SendLivePoints();
LiveArray[TmpOffset] = pAlarm[0];
OLivePointList.GetNext(pos);
}
Offset += AlarmCount*LIVEALMLITSIZE;
for(i=0;i<lightcount;i++)
{
="" otemp="(CTagBase*" )="" olivepointlist.getat(pos);
="" tmpoffset="Offset+(i*LIVEALMLITSIZE);
" unsigned="" char="" *plight="OTemp-">SendLivePoints();
LiveArray[TmpOffset] = pLight[0];
OLivePointList.GetNext(pos);
}
Offset += LightCount*LIVEALMLITSIZE;
}

tData.Init();
for(i=0;i<livedatacount.count;i++)
="" tdata.m_sdata.insert(i,livearray[i]);
="" int="" ilen="tData.m_sData.GetLength();
" tfrm-="">UpdateOprs(&tData);
Sleep(5);

char gAcknowledge[50];
memset(gAcknowledge,0,50);
int clntCount = tFrm->m_connectionList.GetCount();
cData[0].Init();
for(i = 0;i < clntCount;i++)
cData[i].Init();
tFrm->UpdateRequests(cData);
Acknowledge = FALSE;
for(i = 0;i < clntCount;i++)
{
if(cData[i].m_sData.GetLength())
{
gAcknowledge[i] = cData[i].m_sData.GetAt(0);
if(gAcknowledge[i] == TRUE)
{
Acknowledge = gAcknowledge[i];
}
}
}

char cFlag = Acknowledge;
if(InstClosedFlag==TRUE)
Acknowledge = __CLOSED;

tData.Init();
tData.m_sData.Insert(0,Acknowledge);
tFrm->UpdateOprs(&tData);
Sleep(5);

if(cFlag == TRUE)
{
cData[0].Init();
for(i = 0;i < clntCount;i++)
cData[i].Init();
tFrm->UpdateRequests(cData);
Sleep(5);
for(i = 0; i < clntCount;i++)
{
if(gAcknowledge[i] == TRUE)
{
int temp = cData[i].m_sData.GetLength();
for(int j = 0; j < temp; j++)
InstChangeString[j] = cData[i].m_sData.GetAt(j);
ChangeInstValues(InstChangeString);
}
}
}

tData.Init();
char cTemp[200];
CString strTemp;
strTemp.Insert(0,INS_BACKTRACK_TIME);
strTemp.Insert(1,bBackTrkTime);
strTemp.Insert(2,strBackTrkTime);

strcpy(cTemp,strTemp);

int nLenTemp = strTemp.GetLength();
for(i=0;i<nlentemp;i++)
{
="" tdata.m_sdata.insert(i,ctemp[i]);
="" }
="" tfrm-="">UpdateOprs(&tData);

if(bBackTrkTime)
{
strBackTrkTime = "";
bBackTrkTime = false;
}

CString STime;
CTime TNow;
TNow = CTime::GetCurrentTime();
STime=TNow.Format("%H:%M:%S");

tData.Init();
char cCurTime[10];
CString sCurTime;
strcpy(cCurTime,STime);

nLenTemp = STime.GetLength();
for(i=0;i<nlentemp;i++)
{
="" tdata.m_sdata.insert(i,ccurtime[i]);
="" }
="" tfrm-="">UpdateOprs(&tData);
sGblTime = STime;

}








//Client Side Code
void RecvActiveData_Ins()
{
static POSITION pos;
CString tString = "";
long int Offset = 0;
int i = 0;
static char nType = 0;
char czCount[10] = {0};
int nCount = 0;

if( InstClosedFlag_Client == TRUE || OprClosedFlag_Client == TRUE )
return;

CTagBase* OTemp;
CTrans oData;
CMainFrame* tFrm = (CMainFrame*)AfxGetMainWnd();
char sTime[10]={0};

oData.Init(LiveDataCount.Count);
tFrm->ReceiveData(&oData);
int nLen = oData.m_sData.GetLength();
memcpy((void*)LiveArray_Client,(const char*)oData.m_sData,nLen);


char StatusHold=LiveArray_Client[0];

if(StatusHold != nModelHoldSvr)
{
nModelHoldSvr = StatusHold;

if (nModelHoldSvr == 1)
{
CMainFrame *pFrame = (CMainFrame*)AfxGetApp()->m_pMainWnd;
if(Esim->HOLD != 1)
pFrame->OnModePause();
}
else
{
CMainFrame *pFrame = (CMainFrame*)AfxGetApp()->m_pMainWnd;
if(Esim->HOLD != 0)
pFrame->OnModeRun();
}
}

if(LiveArray_Client[0] == 2)
{
IsMsgRecvFromInst = TRUE;
return;
}
else if((pos = goTagList.GetHeadPosition())!=NULL)
{
Offset = 1;
for(i=0;i<giconcnt;i++)
{
="" otemp="(CTagBase*" )="" gotaglist.getat(pos);
="" cstring="" str="OTemp-">GetTagName();
OTemp->ReceiveLivePoints((LiveArray_Client+Offset)+(i*LIVECONSIZE));
char str2=OTemp->GetCascade();
goTagList.GetNext(pos);
}
Offset += giConCnt*LIVECONSIZE;
for(i=0;i<giindcnt;i++)
{
="" otemp="(CTagBase*" )="" gotaglist.getat(pos);
="" otemp-="">ReceiveLivePoints((LiveArray_Client+Offset)+(i*LIVEINDSIZE));
goTagList.GetNext(pos);
}
Offset += giIndCnt*LIVEINDSIZE;
int nSwtESwt = giSwtCnt + giESwtCnt;
for(i=0;i<nswteswt;i++)
{
="" otemp="(CTagBase*" )="" gotaglist.getat(pos);
="" otemp-="">ReceiveLivePoints((LiveArray_Client+Offset)+(i*LIVESWTSIZE));
goTagList.GetNext(pos);
}
Offset += nSwtESwt*LIVESWTSIZE;
for(i=0;i<giglbcnt;i++)
{
="" otemp="(CTagBase*" )="" gotaglist.getat(pos);
="" otemp-="">ReceiveLivePoints((LiveArray_Client+Offset)+(i*LIVEGLBSIZE));
goTagList.GetNext(pos);
}
Offset += giGlbCnt*LIVEGLBSIZE;
int nAlrmLght = giAlrmCnt + giLitCnt;
for(i=0;i<nalrmlght;i++)
{
="" otemp="(CTagBase*" )="" gotaglist.getat(pos);
="" otemp-="">ReceiveLivePoints((LiveArray_Client+Offset)+(i*LIVEALMLITSIZE));
goTagList.GetNext(pos);
}
Offset += nAlrmLght*LIVEALMLITSIZE;
for(i=0;i<giamscnt;i++)
{
="" otemp="(CTagBase*" )="" gotaglist.getat(pos);
="" otemp-="">ReceiveLivePoints((LiveArray_Client+Offset)+(i*LIVEAMSSIZE));
goTagList.GetNext(pos);
}
Offset += giAmsCnt*LIVEAMSSIZE;
}

if(gbValueChange == TRUE)
{
Acknowledge_Client=TRUE;
}
else if(OprClosedFlag_Client==TRUE)
{
Acknowledge_Client=__CLOSED;
}
else
{
Acknowledge_Client=FALSE;
}


char TempString[10] = {0};
oData.Init(1);
oData.m_sData.Insert(0,Acknowledge_Client);
tFrm->SendData(&oData);

oData.Init(1);
tFrm->ReceiveData(&oData);
strcpy(TempString,oData.m_sData);

if(TempString[0] == TRUE)
{
oData.Init(28);
for(i = 0; i < 28; i++)
oData.m_sData.Insert(i,gszModifiedTagInfo[i]);
tFrm->SendData(&oData);
gbValueChange = FALSE;
memset( gszModifiedTagInfo, 0, 28 );
}
else if(TempString[0]==__CLOSED)
{
InstClosedFlag_Client=TRUE;
OprClosedFlag_Client=TRUE;
}
char TempBackTrk[250] = {0};
oData.Init(1);
tFrm->ReceiveData(&oData);
strcpy(TempBackTrk,oData.m_sData);
if(TempBackTrk[0] == INS_BACKTRACK_TIME)
{
if(TempBackTrk[1] == true)
{
bBackTrkTime = true;
ReadBackTime_Ins(TempBackTrk);
}
else
bBackTrkTime = false;
}

char cRecServTime[10] = {0};
oData.Init(1);
tFrm->ReceiveData(&oData);
strcpy(cRecServTime,oData.m_sData);
sGblTime = cRecServTime;
}
GeneralRe: TCP/IP Socket connectivity issue in Internet Pin
Jochen Arndt19-Jun-18 4:33
professionalJochen Arndt19-Jun-18 4:33 
GeneralRe: TCP/IP Socket connectivity issue in Internet Pin
manoharbalu20-Jun-18 19:02
manoharbalu20-Jun-18 19:02 
GeneralRe: TCP/IP Socket connectivity issue in Internet Pin
Jochen Arndt20-Jun-18 21:04
professionalJochen Arndt20-Jun-18 21:04 
GeneralRe: TCP/IP Socket connectivity issue in Internet Pin
manoharbalu21-Jun-18 0:55
manoharbalu21-Jun-18 0:55 
GeneralRe: TCP/IP Socket connectivity issue in Internet Pin
Jochen Arndt21-Jun-18 1:31
professionalJochen Arndt21-Jun-18 1:31 
GeneralRe: TCP/IP Socket connectivity issue in Internet Pin
manoharbalu21-Jun-18 19:36
manoharbalu21-Jun-18 19:36 
GeneralRe: TCP/IP Socket connectivity issue in Internet Pin
Victor Nijegorodov21-Jun-18 20:35
Victor Nijegorodov21-Jun-18 20:35 
GeneralRe: TCP/IP Socket connectivity issue in Internet Pin
Jochen Arndt21-Jun-18 20:55
professionalJochen Arndt21-Jun-18 20:55 
GeneralRe: TCP/IP Socket connectivity issue in Internet Pin
manoharbalu25-Jun-18 19:04
manoharbalu25-Jun-18 19:04 
AnswerRe: TCP/IP Socket connectivity issue in Internet Pin
jschell23-Jun-18 4:52
jschell23-Jun-18 4:52 
Questioninstalled apps Pin
john563217-Jun-18 20:22
john563217-Jun-18 20:22 
AnswerRe: installed apps Pin
Victor Nijegorodov17-Jun-18 20:45
Victor Nijegorodov17-Jun-18 20:45 
GeneralRe: installed apps Pin
john563217-Jun-18 20:53
john563217-Jun-18 20:53 
AnswerRe: installed apps Pin
User 742933817-Jun-18 21:33
professionalUser 742933817-Jun-18 21:33 
GeneralRe: installed apps Pin
john563217-Jun-18 22:58
john563217-Jun-18 22:58 
AnswerRe: installed apps Pin
User 742933817-Jun-18 23:04
professionalUser 742933817-Jun-18 23:04 
QuestionChange Tabs in Ribbon Control dynamically - C++ Pin
Gopi Nath14-Jun-18 2:13
Gopi Nath14-Jun-18 2:13 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.