DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: Socket Error

  1. #1
    Adam Guest

    Socket Error


    Hello,

    My question is about socket. I have funcA in fileX. In funcA I have a socket.
    I can call funcA in fileY but I have a socket error, although I did refine
    the socket with different name. How can I stay away with that 'socket error'?

    Thanks in advance.

    adam

  2. #2
    chris Guest

    Re: Socket Error


    "Adam" <chucha68@hotmail.com> wrote:
    >
    >Hello,
    >
    >My question is about socket. I have funcA in fileX. In funcA I have a socket.
    >I can call funcA in fileY but I have a socket error, although I did refine
    >the socket with different name. How can I stay away with that 'socket error'?
    >
    >Thanks in advance.
    >
    >adam


    posting the specific error code would help. as would posting the applicable
    code. your error code should be in the 10,0xx range if its a winsock error.


  3. #3
    Adam Guest

    Re: Socket Error


    Here is the the func I wanna call. I can call it anywhere withing the same
    class but when I try to call it in another class, I get socket error.

    BOOL CClassX::Func1()
    {
    CSocket SOCK;
    CString stringIP = GetTitle();
    SendCmd(stringIP, SET_NAME_CFG, &SOCK);
    char buff[64];
    sprintf(buff, "%s", m_strName);
    SOCK.Send(buff, strlen(buff));
    SOCK.Close();

    return TRUE;
    }

    Function prototype:

    BOOL SendCmd(const CString& ipAddr, CMDTYPE Cmd, CSocket* pSock=NULL);

    GetTitle() is a MFC member which return an IP address.

    I'm trying to call Func1 in OK function of another class:

    void CNameCfg::OnOK()
    {
    UpdateData();
    // TODO: Add extra validation here
    CClassX A;
    A.Func1();
    CDialog::OnOK();
    }


    When I call this func1, I can't get IP address in GetTitle() and m_strName
    which I can get them all if I call it within the same class.

    >
    >posting the specific error code would help. as would posting the applicable
    >code. your error code should be in the 10,0xx range if its a winsock error.
    >



  4. #4
    chris Guest

    Re: Socket Error


    with the qualification that i'm not an mfc guy, so take this advice with a
    grain of salt...

    "Adam" <chucha68@hotmail.com> wrote:
    >
    >Here is the the func I wanna call. I can call it anywhere withing the same
    >class but when I try to call it in another class, I get socket error.
    >
    >BOOL CClassX::Func1()
    >{
    > CSocket SOCK;
    > CString stringIP = GetTitle();


    this looks like a call using the this ptr (i.e. equivalent to
    'this->GetTitle()'

    > SendCmd(stringIP, SET_NAME_CFG, &SOCK);
    > char buff[64];
    > sprintf(buff, "%s", m_strName);
    > SOCK.Send(buff, strlen(buff));
    > SOCK.Close();
    >
    > return TRUE;
    >}
    >
    >Function prototype:
    >
    >BOOL SendCmd(const CString& ipAddr, CMDTYPE Cmd, CSocket* pSock=NULL);
    >
    >GetTitle() is a MFC member which return an IP address.


    this function is a member of CDocument isnt it? that means that CClassX
    derives from CDocument - is that true?

    >
    >I'm trying to call Func1 in OK function of another class:
    >
    >void CNameCfg::OnOK()
    >{
    > UpdateData();
    > // TODO: Add extra validation here
    > CClassX A;


    If the above is true, then this line indicates that you are instantiating
    a local copy of a CDocument object. Not the same copy that exists already
    within the doc-frame-view architecture.

    > A.Func1();
    > CDialog::OnOK();
    >}
    >
    >
    >When I call this func1, I can't get IP address in GetTitle() and m_strName
    >which I can get them all if I call it within the same class.
    >
    >>
    >>posting the specific error code would help. as would posting the applicable
    >>code. your error code should be in the 10,0xx range if its a winsock error.
    >>

    >


    again, i'm not an mfc guy - so all this could be bogus advice. but, it seems
    like your problems are related to instantiating a local CDoc object instead
    of calling AfxGetApp()->GetDocument()



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center