Click here to Skip to main content
15,885,216 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionGraphics.lib - that old one Pin
liquid_5-Jul-12 1:39
liquid_5-Jul-12 1:39 
AnswerRe: Graphics.lib - that old one Pin
Richard MacCutchan5-Jul-12 2:30
mveRichard MacCutchan5-Jul-12 2:30 
AnswerRe: Graphics.lib - that old one Pin
Chris Losinger5-Jul-12 5:07
professionalChris Losinger5-Jul-12 5:07 
GeneralRe: Graphics.lib - that old one Pin
Software_Developer5-Jul-12 6:59
Software_Developer5-Jul-12 6:59 
QuestionHelp about Windows Batch file. Pin
pix_programmer4-Jul-12 18:45
pix_programmer4-Jul-12 18:45 
AnswerRe: Help about Windows Batch file. Pin
Jochen Arndt4-Jul-12 21:20
professionalJochen Arndt4-Jul-12 21:20 
GeneralHow to evaluate the ACPI method that requires arguments? Pin
ashok.jeev4-Jul-12 3:28
ashok.jeev4-Jul-12 3:28 
QuestionCResource execption Pin
ForNow3-Jul-12 15:40
ForNow3-Jul-12 15:40 
Hi,

I am trying to start 4 socket connections (same IP different socket) with each running in thier own threads

here is the class defination for the Derived CWinThread

C++
class SockCLeintThread : public CWinThread {
   public:
	   //   DECLARE_DYNCREATE(SockCLeintThread)
      //  DECLARE_DYNAMIC(SockCLeintThread)
       //     IMPLEMENT_DYNAMIC(SockCLientThread)
        public:
		SockCLeintThread(UINT myport);
		~SockCLeintThread();
                CWnd *sendwindow;
                CWnd *call_wnd;
       		char *thread_id;
                SockClient thisocket;            // Socket to do ocommunication
                virtual BOOL InitInstance();      // Just for starters
                void Sendit(WPARAM, LPARAM);
		void Receiveit(WPARAM, LPARAM);
		LPCTSTR ipaddr;
                BOOL idle;				 // looking for work
		allexceptions myallexception;
				 
		struct {
			unsigned int is_connected : 1;
			unsigned int busy : 1;
			} flags;
				
protected:
           DECLARE_MESSAGE_MAP()

};

Class defination for the derived CAsynSocket Class
C++
class SockClient : public CAsyncSocket
{
 public:
      // SockCleint(char *sockptr);
         SockClient(UINT myport);
         char *sockbuffer;		// send and receive buffer
         int num_buff;
	CWnd *send_wnd;
	int thread_no;
	UINT port;
	private:
		int busy;               // inuse
		               // port used by this class
   protected:
                         // window to send message to
        virtual void OnReceive(int nErrorCode);
        virtual void OnSend(int nErrorCode);
        virtual void OnConnect(int nErrorCode);
		virtual void OnClose(int nErrorCode);


the custructor for the CwinThread takes a port #

I start these threads in My CwinApp::Initinstance

here is the loop

C++
     for (i = 0, start_port = 11007; i < 4; start_port++, i++)
{
        threadptr[i] = new SockCLeintThread(start_port);

      if (threadptr[i] == NULL)
         m_pMainWnd->MessageBox("SockClientThreadFail",NULL,MB_ICONERROR);

          threadptr[i]->CreateThread(CREATE_SUSPENDED,0,NULL);

          threadptr[i]->flags.is_connected = 0;

           threadptr[i]->ipaddr = "192.168.1.4";                   // ip address

           SetThreadName(threadptr[i]->m_nThreadID,thread[i]);

             threadptr[i]->ResumeThread();

    }


Here is the constrocter of the dervived CwinThread
C++
SockCLeintThread::SockCLeintThread(UINT myport) : thisocket(myport)
{
        m_bAutoDelete = FALSE;
}


The Constructer for the derived CAsynSocket
C++
SockClient::SockClient(UINT myport)
 {
	port = myport;
        sockbuffer = new char[300];

 }


in the CwinThread::initinstance is were is I create the socket and try to connect
C++
 OOL SockCLeintThread::InitInstance()
   {
int error_code;
MSG m_msgCur;
extern void SetThreadName( DWORD dwThreadID, LPCSTR szThreadName);
         



	 
		 if(thisocket.Create(thisocket.port,SOCK_STREAM,NULL)== 0)
         {
                         error_code =  GetLastError();
                  }

             if (thisocket.AsyncSelect   (FD_CONNECT|FD_CLOSE|FD_OOB|FD_ACCEPT) == 0) 
			                   error_code =  GetLastError();
			 

       

          


          if( thisocket.Connect(ipaddr,thisocket.port) == 0)
                  {
		                         error_code =  GetLastError();
                  }
		   else
				 	  flags.is_connected = 1;
		  
			   
  PeekMessage(&m_msgCur, NULL, NULL, NULL, PM_NOREMOVE);   // Create Message Queue



    return TRUE;                                                   // [11]
   }


I have step thru this code numerous times an have gotten exception st different points but mostly at the CAsynSocket::Create

If I am not going about this right way please let me know
AnswerRe: CResource execption Pin
Richard MacCutchan3-Jul-12 22:23
mveRichard MacCutchan3-Jul-12 22:23 
GeneralRe: CResource execption Pin
ForNow4-Jul-12 2:18
ForNow4-Jul-12 2:18 
GeneralRe: CResource execption Pin
Richard MacCutchan4-Jul-12 3:35
mveRichard MacCutchan4-Jul-12 3:35 
GeneralI inserted IMPLEMENT_SERIAL, DECLARE_SERIAL can someone explain the usage the Run time macros Pin
ForNow4-Jul-12 12:17
ForNow4-Jul-12 12:17 
GeneralAND IT WORKED fogot that part Pin
ForNow4-Jul-12 12:18
ForNow4-Jul-12 12:18 
GeneralRe: I inserted IMPLEMENT_SERIAL, DECLARE_SERIAL can someone explain the usage the Run time macros Pin
Richard MacCutchan4-Jul-12 21:49
mveRichard MacCutchan4-Jul-12 21:49 
QuestionProblem in writing values to shared memory from another process Pin
manoharbalu3-Jul-12 2:41
manoharbalu3-Jul-12 2:41 
AnswerRe: Problem in writing values to shared memory from another process Pin
Richard Andrew x644-Jul-12 12:46
professionalRichard Andrew x644-Jul-12 12:46 
GeneralRe: Problem in writing values to shared memory from another process Pin
manoharbalu4-Jul-12 19:14
manoharbalu4-Jul-12 19:14 
QuestionA guide or survey on software integration techniques Pin
m.salsal2-Jul-12 20:33
m.salsal2-Jul-12 20:33 
AnswerRe: A guide or survey on software integration techniques Pin
Maximilien3-Jul-12 0:48
Maximilien3-Jul-12 0:48 
GeneralRe: A guide or survey on software integration techniques Pin
hr.nasr6-Jul-12 20:48
hr.nasr6-Jul-12 20:48 
GeneralRe: A guide or survey on software integration techniques Pin
Maximilien7-Jul-12 3:28
Maximilien7-Jul-12 3:28 
Questionhow abstract and interface used in real time application? Pin
shanmugarajaa2-Jul-12 19:27
shanmugarajaa2-Jul-12 19:27 
AnswerRe: how abstract and interface used in real time application? Pin
_AnsHUMAN_ 2-Jul-12 19:57
_AnsHUMAN_ 2-Jul-12 19:57 
AnswerRe: how abstract and interface used in real time application? Pin
Richard MacCutchan2-Jul-12 21:36
mveRichard MacCutchan2-Jul-12 21:36 
QuestionStrange compiler output Pin
ForNow2-Jul-12 17:50
ForNow2-Jul-12 17:50 

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.