Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. When should I delete ServerSocket when client shutdown

When should I delete ServerSocket when client shutdown

Scheduled Pinned Locked Moved C / C++ / MFC
questionsysadminhelplearning
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • W Offline
    W Offline
    white jungle
    wrote on last edited by
    #1

    When client shutdown,it will send a FD_CLOSE to server and the server receive this message,then the server invoke the function OnClose().In this function I want to destruct the server socket object.BUt how can I? In my program(it's a dialog based program with socket support),the var m_ConnectList used to record how many ServerSocket have been create. void CBBSServerDlg::ClientConnect() { m_pServer=new CServeSocket(); if(m_Listen.Accept(*m_pServer)) { m_ConnectList.AddTail(m_pServer); m_pServer->Init(this); UpdateData(FALSE); } else { delete m_pServer; m_pServer=NULL; } } this function will be called by a CListenSocket when it received a FD_ACCEPT. So I want to destruct the serversocket object when client shutdown with the following code void CBBSServerDlg::LostClient(CServeSocket* pSocket) { ASSERT(pSocket!=NULL); POSITION pos=m_ConnectList.Find(pSocket,NULL); if(pos!=NULL) { m_ConnectList.RemoveAt(pos); } pSocket->Close(); delete pSocket; pSocket=NULL; } And of course the function is called by ServerSocket when received a FD_CLOSE. void CServeSocket::OnClose(int nErrorCode) { m_pMainDlg->LostClient(this); CSocket::OnClose(nErrorCode); } Now I have a question that if I call the function LostClient,the ServerSocket will be destroyed ,and the where the function returned. But if I don't do it this way,How can I destroy the ServerSocket object when client shutdown Thank you very much for your help! Don't look at me in that way!

    V 1 Reply Last reply
    0
    • W white jungle

      When client shutdown,it will send a FD_CLOSE to server and the server receive this message,then the server invoke the function OnClose().In this function I want to destruct the server socket object.BUt how can I? In my program(it's a dialog based program with socket support),the var m_ConnectList used to record how many ServerSocket have been create. void CBBSServerDlg::ClientConnect() { m_pServer=new CServeSocket(); if(m_Listen.Accept(*m_pServer)) { m_ConnectList.AddTail(m_pServer); m_pServer->Init(this); UpdateData(FALSE); } else { delete m_pServer; m_pServer=NULL; } } this function will be called by a CListenSocket when it received a FD_ACCEPT. So I want to destruct the serversocket object when client shutdown with the following code void CBBSServerDlg::LostClient(CServeSocket* pSocket) { ASSERT(pSocket!=NULL); POSITION pos=m_ConnectList.Find(pSocket,NULL); if(pos!=NULL) { m_ConnectList.RemoveAt(pos); } pSocket->Close(); delete pSocket; pSocket=NULL; } And of course the function is called by ServerSocket when received a FD_CLOSE. void CServeSocket::OnClose(int nErrorCode) { m_pMainDlg->LostClient(this); CSocket::OnClose(nErrorCode); } Now I have a question that if I call the function LostClient,the ServerSocket will be destroyed ,and the where the function returned. But if I don't do it this way,How can I destroy the ServerSocket object when client shutdown Thank you very much for your help! Don't look at me in that way!

      V Offline
      V Offline
      valikac
      wrote on last edited by
      #2

      I am not familiar with winsock wrapper classes. Under raw winsock, one solution is closesocket(). Kuphryn

      W 1 Reply Last reply
      0
      • V valikac

        I am not familiar with winsock wrapper classes. Under raw winsock, one solution is closesocket(). Kuphryn

        W Offline
        W Offline
        white jungle
        wrote on last edited by
        #3

        As a matter of fact,I just want to know the things following. I have two classes claas B; class A { ....... void create(); void destroy(B *pB) } clss B { void SetAttach(A * pA){m_pA=pA;} A m_pA; } ....... A::Create() { B b; } A::Destroy(B *pB) { pB->destroy(); delete pB; pB=NULL; } and if I invoke A::Destroy(B *pB)from class B b::someFunction() { m_pA->Destroy(this); } I think it will be throw out a error because the function can't be returned when pB was deleted. So I want to get a useful method to delete pB For my poor,wish you can understand me! Don't look at me in that way!

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups