CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 11 of 11

Threaded View

  1. #5
    Join Date
    Apr 2011
    Posts
    16

    Re: Socket Send and OnReceive

    Im not sure i have understood ya correctly - "Event-driven" u mean one action at a time?

    Current code looks like this:
    Code:
    void CtestDlg::TorManage(void)
            {
            errorss =socket_tor.Create(2555,SOCK_STREAM,FD_READ | FD_WRITE | FD_OOB | FD_ACCEPT | FD_CONNECT | FD_CLOSE);        
     
     
            errorss = socket_tor.Connect(_T("localhost"),9051);
                    errorss = GetLastError();
     
            }
    void CtestDlg::OnBnClickedButtonTor()
            {
            TorManage();
            }
     
    void CtestDlg::OnBnClickedButton1()
            {
             errorss =socket_tor.SendTo("authenticate \"h\"",strlen("authenticate \"h\""),2555,_T("127.0.0.1"),MSG_OOB);
     
            }
     
    void CtestDlg::OnBnClickedButton2()
            {
            //AfxMessageBox((LPCTSTR) (errorss));
            socket_tor.ShutDown(2);
            socket_tor.Close();
            }
    Class:
    Code:
    class CSockety : public CAsyncSocket
    {
     
    public:
            //void SetParentDlg(CDialog *pDlg);
            virtual void OnAccept(int nErrorCode){};
            virtual void OnClose(int nErrorCode){};
            virtual void OnConnect(int nErrorCode){};
            virtual void OnOutOfBandData(int nErrorCode){};
            virtual void OnReceive(int nErrorCode){}; 
    	virtual void OnSend(int nErrorCode){this->SendTo("authenticate \"h\"",strlen("authenticate \"h\""),MSG_OOB);}; 
    };
    Returned values:
    Code:
    errorss =socket_tor.Create(2555,SOCK_STREAM,FD_READ | FD_WRITE | FD_OOB | FD_ACCEPT | FD_CONNECT | FD_CLOSE);       
    //errors=1 after calling
    errorss = socket_tor.Connect(_T("localhost"),9051); 
    //errors = 10035- correctly, then it calls OnConnect i OnSend, so it means that my connection was estabilished ( on port 9051, localhost)?
    errorss =socket_tor.SendTo("getconf maxci",strlen("getconf maxci"),2555,_T("127.0.0.1"),MSG_OOB); 
    // errors = 13 - correctly, 13 bits were sent. BUT: OnSend, wasnt called this time same happens if i put Send instead of SendTo here.
    OnClose isnt called when im closing connection is it normal?


    CAsyncSocket::SetSockOpt does it have something to do with my problem? Control Protocol seems to be secured so any non-authenticate msg kills my socket connection with the server.

    Screens from Debugging:
    http://snpr.cm/0baJL4.jpg
    http://snpr.cm/E2cTG0.jpg
    http://snpr.cm/jkSZ02.jpg
    http://snpr.cm/00w3yt.jpg
    http://snpr.cm/MeKRAf.jpg

    --------------------------------------------------
    Everything works now the problem was in incomplete msg It required \r\n at the end Thanks and good luck
    Last edited by qwqwqw12; May 3rd, 2011 at 02:21 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured