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. CAsyncSocket Server

CAsyncSocket Server

Scheduled Pinned Locked Moved C / C++ / MFC
helpc++sysadmin
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.
  • B Offline
    B Offline
    Billar
    wrote on last edited by
    #1

    Dear Friends, I am using CAsyncSocket and CSocket for writting a server program. In AsyncSocket I am using virtual void OnAccept(int nErrorCode); virtual void OnClose(int nErrorCode); virtual void OnReceive(int nErrorCode); and also in Socket I am using virtual void OnAccept(int nErrorCode); virtual void OnClose(int nErrorCode); virtual void OnConnect(int nErrorCode); virtual void OnReceive(int nErrorCode); Also in the dlg.cpp file, At InitDialog I am writting m_cSocketServer.Create(4000); m_cSocketServer.Listen(); m_cAsyncSocketServer.Create(4000); m_cSocketServer.Listen(); Also at the Onbutton message I am checking and writting a message into a display like this void CMFCServerDlg::OnButtonConnection() { // TODO: この位置にコントロール通知ハンドラ用のコードを追加してください char DispBuf[256]; if(m_cSocketServer.Create(4000) && m_cSocketServer.Listen()){ sprintf(DispBuf, "Server Started"); AfxGetMainWnd()->GetDlgItem(IDC_STATIC)->SetWindowText(DispBuf); } else{ sprintf(DispBuf, "Connection Failed"); AfxGetMainWnd()->GetDlgItem(IDC_STATIC)->SetWindowText(DispBuf); } For other reference.... LRESULT CMFCServerDlg::OnAccept(WPARAM wParam, LPARAM lParam) { m_cSocketServer.Accept(m_cAsyncSocketServer); DestroyFlag = TRUE; return 0; } This is a user message send by the AsyncSocket and Socket from OnAcceptMessage.... My applicaion is very simple and with the above code it is not working. Will you please help to detect the error. Why this code is not suitable to develop a simple server. Here, I have a dialog box with one button and a text box. Button is for to start a server and text box is nothing but to display a message that server is started. Please help me to find out the solution. Thanking You in advance. Billar

    T 1 Reply Last reply
    0
    • B Billar

      Dear Friends, I am using CAsyncSocket and CSocket for writting a server program. In AsyncSocket I am using virtual void OnAccept(int nErrorCode); virtual void OnClose(int nErrorCode); virtual void OnReceive(int nErrorCode); and also in Socket I am using virtual void OnAccept(int nErrorCode); virtual void OnClose(int nErrorCode); virtual void OnConnect(int nErrorCode); virtual void OnReceive(int nErrorCode); Also in the dlg.cpp file, At InitDialog I am writting m_cSocketServer.Create(4000); m_cSocketServer.Listen(); m_cAsyncSocketServer.Create(4000); m_cSocketServer.Listen(); Also at the Onbutton message I am checking and writting a message into a display like this void CMFCServerDlg::OnButtonConnection() { // TODO: この位置にコントロール通知ハンドラ用のコードを追加してください char DispBuf[256]; if(m_cSocketServer.Create(4000) && m_cSocketServer.Listen()){ sprintf(DispBuf, "Server Started"); AfxGetMainWnd()->GetDlgItem(IDC_STATIC)->SetWindowText(DispBuf); } else{ sprintf(DispBuf, "Connection Failed"); AfxGetMainWnd()->GetDlgItem(IDC_STATIC)->SetWindowText(DispBuf); } For other reference.... LRESULT CMFCServerDlg::OnAccept(WPARAM wParam, LPARAM lParam) { m_cSocketServer.Accept(m_cAsyncSocketServer); DestroyFlag = TRUE; return 0; } This is a user message send by the AsyncSocket and Socket from OnAcceptMessage.... My applicaion is very simple and with the above code it is not working. Will you please help to detect the error. Why this code is not suitable to develop a simple server. Here, I have a dialog box with one button and a text box. Button is for to start a server and text box is nothing but to display a message that server is started. Please help me to find out the solution. Thanking You in advance. Billar

      T Offline
      T Offline
      toxcct
      wrote on last edited by
      #2

      do you have an error at compile time or run time ? what does it say to you ?


      TOXCCT >>> GEII power

      B 1 Reply Last reply
      0
      • T toxcct

        do you have an error at compile time or run time ? what does it say to you ?


        TOXCCT >>> GEII power

        B Offline
        B Offline
        Billar
        wrote on last edited by
        #3

        Dear Freinds, Thank you all for the information and kind response. MY problem is solved. Actually the problem was at the client side. I was not initializing the socket at the client side at InitInstance. But now it is solved. Thank you once again for everything. Bye Billar:):-O

        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