Click to See Complete Forum and Search --> : Socket Programming-Urgent Requirement


Billar
June 13th, 2004, 01:28 AM
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
:thumb: :mad: :confused:

Andreas Masur
June 13th, 2004, 04:26 AM
[Moved thread]

Billar
June 13th, 2004, 05:35 AM
Dear Andreas Masur,

I couldn't get any thing from the link you provided. How allocator is useful to use the socket programming.

Please write to me and correct my code and please describe the error I am making in respect to getting the result.

If you need any more information please write to me.

Waiting for your response soon.

With Regards,

Billar

Andreas Masur
June 13th, 2004, 05:49 AM
Well...the link was not supposed to help with your question...I did not answer your question, I simply moved your question to the appropriate forum...

Yasoo
June 13th, 2004, 09:37 AM
Billar -

I made a tutorial for a bare-bones client/server app using TCP or UDP. Check out the "MFC Sockets sample" on my webpage:

http://home.comcast.net/~zplusplus/

It's VERY basic (no error checking, etc). I included tidbits of information explaining why you sometimes might get errors. Beyond the basic things, there can be a lot that goes wrong with routing and such. First, try the client and the server on the same computer and see if you can get them to communicate. Then, try client on one computer and server on another in the same internal network. Then expand out from there.