Click here to Skip to main content
15,888,286 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionHandling keystrokes on TreeCntrl Pin
ratprita16-Oct-09 1:04
ratprita16-Oct-09 1:04 
AnswerRe: Handling keystrokes on TreeCntrl Pin
Hans Dietrich16-Oct-09 1:40
mentorHans Dietrich16-Oct-09 1:40 
Questionshow/hide CWebBrowser2 Pin
includeh1016-Oct-09 1:02
includeh1016-Oct-09 1:02 
AnswerRe: show/hide CWebBrowser2 Pin
Steve Thresher16-Oct-09 3:55
Steve Thresher16-Oct-09 3:55 
QuestionMFC Resource File Pin
Caslen16-Oct-09 0:16
Caslen16-Oct-09 0:16 
AnswerRe: MFC Resource File Pin
Hans Dietrich16-Oct-09 1:42
mentorHans Dietrich16-Oct-09 1:42 
GeneralRe: MFC Resource File Pin
Caslen16-Oct-09 2:22
Caslen16-Oct-09 2:22 
Questionmultithreaded TCP Server Application(MFC) Pin
Manmohan2915-Oct-09 23:51
Manmohan2915-Oct-09 23:51 
I am writing a multithreaded TCP Server Application(MFC).
I have written simple TCP server earlier n it worked fine. The tutorial I used told that for

multithreaded server I have to use more than one Socket variable and It also told that the server

should spin individual thread for every client.

But I think I am writing wrong code.

Where am I going wrong? any suggestions please.
My Code looks like this:-

// Declarations of functions and variables.

class CsockDlg : public CDialog
{
// Construction
public:
	CsockDlg(CWnd* pParent = NULL);	// standard constructor

// Dialog Data
	.
	
	.

	.
private:
	CMySocket m_sListenSocket;
	CMySocket m_sConnectSocket;
public:
	void OnAccept(void);
	void OnConnect(void);
	void OnClose(void);
	void OnReceive(void);
	void OnSend(void);
	static UINT ThreadServer(LPVOID pParam);
	void TS(void);
};

// Definitions of functions of CsockDlg Class.

BOOL CsockDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Add "About..." menu item to system menu.

	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	.

	.

	.

	// TODO: Add extra initialization here
	int m_iPort = 4000;	// Default port for listening connections

	m_sListenSocket.Create(m_iPort);	// Create listening socket
	m_sListenSocket.Listen();	// Start listening on that port

	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CsockDlg::OnAccept(void)
{
	//m_sListenSocket.Accept(m_sConnectSocket);
	AfxBeginThread(ThreadServer, this);	// Spin thread for every client
}

UINT CsockDlg::ThreadServer(LPVOID pParam)
{
	CsockDlg* O = (CsockDlg*)pParam;
	CMySocket c;
	O->m_sListenSocket.Accept(c);
	return 0;
}


Future Lies in Present.
Manmohan Bishnoi

AnswerRe: multithreaded TCP Server Application(MFC) Pin
Moak16-Oct-09 0:16
Moak16-Oct-09 0:16 
GeneralRe: multithreaded TCP Server Application(MFC) Pin
Manmohan2916-Oct-09 0:26
Manmohan2916-Oct-09 0:26 
GeneralRe: multithreaded TCP Server Application(MFC) Pin
Moak16-Oct-09 0:44
Moak16-Oct-09 0:44 
QuestionCalculate factorial of any number less than 10000,but I don't know how to start with? Pin
milestanley15-Oct-09 22:08
milestanley15-Oct-09 22:08 
AnswerRe: Calculate factorial of any number less than 10000,but I don't know how to start with? Pin
Rajesh R Subramanian15-Oct-09 22:19
professionalRajesh R Subramanian15-Oct-09 22:19 
AnswerRe: Calculate factorial of any number less than 10000,but I don't know how to start with? Pin
CPallini15-Oct-09 22:52
mveCPallini15-Oct-09 22:52 
AnswerRe: Calculate factorial of any number less than 10000,but I don't know how to start with? [modified] Pin
CPallini15-Oct-09 23:05
mveCPallini15-Oct-09 23:05 
AnswerRe: Calculate factorial of any number less than 10000,but I don't know how to start with? Pin
David Crow16-Oct-09 3:05
David Crow16-Oct-09 3:05 
AnswerRe: Calculate factorial of any number less than 10000,but I don't know how to start with? Pin
Maximilien16-Oct-09 3:06
Maximilien16-Oct-09 3:06 
GeneralRe: Calculate factorial of any number less than 10000,but I don't know how to start with? Pin
Rajesh R Subramanian16-Oct-09 3:58
professionalRajesh R Subramanian16-Oct-09 3:58 
GeneralRe: Calculate factorial of any number less than 10000,but I don't know how to start with? Pin
Maximilien16-Oct-09 4:02
Maximilien16-Oct-09 4:02 
GeneralRe: Calculate factorial of any number less than 10000,but I don't know how to start with? Pin
David Crow16-Oct-09 4:22
David Crow16-Oct-09 4:22 
QuestionOutlook contacts Pin
Anil Kumar.Arvapalli15-Oct-09 19:59
Anil Kumar.Arvapalli15-Oct-09 19:59 
AnswerRe: Outlook contacts Pin
CPallini15-Oct-09 20:58
mveCPallini15-Oct-09 20:58 
AnswerRe: Outlook contacts Pin
Richard MacCutchan15-Oct-09 22:08
mveRichard MacCutchan15-Oct-09 22:08 
Questionunicode exe with ansi dll Pin
includeh1015-Oct-09 18:01
includeh1015-Oct-09 18:01 
AnswerRe: unicode exe with ansi dll Pin
Hans Dietrich15-Oct-09 19:14
mentorHans Dietrich15-Oct-09 19:14 

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.