Click here to Skip to main content
15,890,282 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: A CxImage Problem (CXX0030: Error: expression can not be evaluated) Pin
ElizabethC8-Jan-04 5:55
ElizabethC8-Jan-04 5:55 
Generalshell programming books Pin
ns7-Jan-04 8:44
ns7-Jan-04 8:44 
GeneralRe: shell programming books Pin
Christian Graus7-Jan-04 10:04
protectorChristian Graus7-Jan-04 10:04 
GeneralRe: shell programming books Pin
Michael Dunn7-Jan-04 10:39
sitebuilderMichael Dunn7-Jan-04 10:39 
GeneralRe: shell programming books Pin
ns8-Jan-04 2:00
ns8-Jan-04 2:00 
GeneralGetting status from mshtml using a UrlMoniker Pin
Andy Brummer7-Jan-04 8:32
sitebuilderAndy Brummer7-Jan-04 8:32 
GeneralRunning or Detecting a print job Pin
kbsoftware7-Jan-04 8:02
kbsoftware7-Jan-04 8:02 
GeneralError occured when using CArchive to send Message ?Please do me a favor for it! Pin
white jungle7-Jan-04 7:54
white jungle7-Jan-04 7:54 
I am learning using CSocket to send/receive message through net,but here's some problem
I use class CSocket CSocketFile CArchive to support my program.
At first,I create a new CSocket object and connect to Server,and everything is OK.At the server I can get the connection message from the client.
After that,I use the following code to send some message to Server:
<br />
CString    str;<br />
    str.Format("%s","risking");<br />
    UINT    CtrlCode;<br />
    CtrlCode=USER_NAME;<br />
    m_pClientSocket->SetSendData(CtrlCode,str,3,1);<br />
    m_pClientSocket->SendData();<br />
//    Sleep(100);<br />
    CtrlCode=USER_PASSWORD;<br />
    m_pClientSocket->SetSendData(CtrlCode,str,3,2);<br />
    m_pClientSocket->SendData();<br />
//    Sleep(100);<br />
    CtrlCode=USER_LOGIN_END;<br />
    str="";<br />
    m_pClientSocket->SetSendData(CtrlCode,str,3,2);<br />
    m_pClientSocket->SendData();<br />

if I add the two code sleep(100);in it,everything looks OK at server,I can see the ctrl_code USER_NAME USER_PASSWORD CTL_END at server.But if I delete the two sleep(100),I can sometimes see all three ctrl_code,sometimes can only see CTRL_END message.
I don't know where is wrong,and the following code is used to send data:
<br />
void CClientSocket::SendData()<br />
{<br />
    CCommand    cmd;<br />
    cmd.m_CtrlCode=m_CtrlCode;<br />
    cmd.m_DataStr=m_DataStr;<br />
    cmd.m_CurrentData=m_CurrentData;<br />
    cmd.m_TotalData=m_TotalData;<br />
    cmd.Serialize(*m_pArchiveOut);//m_pFile=new CSocketFile(this);<br />
                           //m_pArchiveOut=new CArchive(m_pFile,CArchive::store);<br />
    m_pArchiveOut->Flush();<br />
}<br />


At server I use the following code to receive message:
<br />
void CServeSocket::OnReceive(int nErrorCode) <br />
{<br />
    CCommand    cmd;<br />
    do <br />
    {<br />
        cmd.Serialize(*m_pArchiveIn);    <br />
    } while(!m_pArchiveIn->IsBufferEmpty());<br />
    UINT CtrlCode=cmd.m_CtrlCode;<br />
switch(CtrlCode/100)<br />
    {<br />
    case 1:UserLogin(&cmd);<br />
……………….<br />
}<br />
 <br />
void CServeSocket::UserLogin(CCommand *pCmd)<br />
{<br />
    <br />
    switch(pCmd->m_CtrlCode%100)<br />
    {<br />
    case 1:m_LogInUserName=pCmd->m_DataStr;m_LoginDataCount++;<br />
        break;<br />
    case 2:m_LoginUserPwd=pCmd->m_DataStr;m_LoginDataCount++;<br />
        break;<br />
    default:break;<br />
    }<br />
if(m_LoginDataCount>=2)//m_loginDataCount初始化为0<br />
    {<br />
        CCommand    cmd;<br />
        if(m_bLogin=m_DBCtrl.VerifyLogin(m_LogInUserName,m_LoginUserPwd))<br />
        {<br />
            //login successfully<br />
            cmd.m_CtrlCode=USER_LOGIN_SUCCESSFULLY;<br />
            cmd.m_DataStr="You are Welcome!";<br />
        }<br />
        else<br />
        {<br />
            cmd.m_CtrlCode=USER_LOGIN_DENY;<br />
            cmd.m_DataStr="Sorry!You have no privilege to login";<br />
        }<br />
        cmd.m_TotalData=1;<br />
        cmd.m_CurrentData=2;<br />
        <br />
        cmd.Serialize(*m_pArchiveOut);<br />
        m_pArchiveOut->Flush();<br />
        m_LoginDataCount=0;<br />
 <br />
    }<br />
}<br />
 <br />

I really don't know why the server can get all message sending by client.
May anyone do me a favor for it,I just want to know what casue it and how to solve it,Thank you very much

Confused | :confused:

Don't look at me in that way!
GeneralRe: Error occured when using CArchive to send Message ?Please do me a favor for it! Pin
RobJones7-Jan-04 8:17
RobJones7-Jan-04 8:17 
Generaloutput of external program Pin
gfds7-Jan-04 6:08
gfds7-Jan-04 6:08 
GeneralRe: output of external program Pin
Ted Ferenc7-Jan-04 6:48
Ted Ferenc7-Jan-04 6:48 
GeneralRe: output of external program Pin
valikac7-Jan-04 7:24
valikac7-Jan-04 7:24 
GeneralResolving mail server name Pin
Anonymous7-Jan-04 6:04
Anonymous7-Jan-04 6:04 
GeneralRe: Resolving mail server name Pin
valikac7-Jan-04 7:26
valikac7-Jan-04 7:26 
QuestionHow do i disable a popup menu item in runtime? Pin
oren frenkel7-Jan-04 5:33
oren frenkel7-Jan-04 5:33 
AnswerRe: How do i disable a popup menu item in runtime? Pin
Iain Clarke, Warrior Programmer7-Jan-04 6:05
Iain Clarke, Warrior Programmer7-Jan-04 6:05 
GeneralCalculate the Array search time in millisecondes Pin
naif6207-Jan-04 5:04
naif6207-Jan-04 5:04 
GeneralRe: Calculate the Array search time in millisecondes Pin
David Crow7-Jan-04 8:49
David Crow7-Jan-04 8:49 
GeneralRe: Calculate the Array search time in millisecondes Pin
naif6208-Jan-04 4:50
naif6208-Jan-04 4:50 
GeneralRe: Calculate the Array search time in millisecondes Pin
David Crow8-Jan-04 6:04
David Crow8-Jan-04 6:04 
QuestionIs this good form? Pin
Cloaca7-Jan-04 4:49
Cloaca7-Jan-04 4:49 
AnswerRe: Is this good form? Pin
Christian Graus7-Jan-04 10:05
protectorChristian Graus7-Jan-04 10:05 
GeneralRe: Is this good form? Pin
Cloaca7-Jan-04 11:53
Cloaca7-Jan-04 11:53 
AnswerRe: Is this good form? Pin
Mike Dimmick8-Jan-04 2:27
Mike Dimmick8-Jan-04 2:27 
GeneralRe: Is this good form? Pin
Cloaca8-Jan-04 5:02
Cloaca8-Jan-04 5:02 

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.