|
Dear Friends,
I would like To Send my "Case" Object From One Client To Any Other Clients (whom I would Target To) Through My Server.The Server is to be Multithreaded.I would like to Use CSocketFile Class to make the Transfer from Client To Server And Then ,from Server To Other Client(s).
I am Presenting My "Case" Class , to enable you to help me better.I would like to know which Classes I need To Build and where.I am very new to Socket Programming,I need the Architecture.
Class CCase
{
protected:
char CaseID[10];
char CaseName[20];
int ConsultationCount;
public:
char* GetCaseID();
void SetCaseID(char NewCaseID[10]);
char* GetCaseName();
void SetCaseName(char NewCaseName[20]);
int GetConsultationCount();
void SetConsultationCount(int NewConsultationCount);
};
Also, Apart From the Above declarations,my Case Class Also Contains some objects (of Other Classes,I used) as members.
Just Have A Look At My Code :
*************************************************************
//Case.cpp
IMPLEMENT_SERIAL (CCase,CObject,1)
void CCase::Serialize(CArchive& ar)
{
CObject::Serialize (ar);
if(ar.IsStoring ())
{
ar.Read (this->CaseID ,20);
ar.Read (this->CaseName,20);
ar.Read ((void*)this->ConsultationCount,100) ;
ar.Flush ();
}
else if(ar.IsLoading())
{
ar.Write (this->CaseID,20 );
ar.Write(this->CaseName ,20);
ar.Write ((void*)this->ConsultationCount,100 );
ar.Flush ();
}
}
char* CCase::GetCaseID()
{
return this->CaseID ;
}
void CCase::SetCaseID(char NewCaseID[10])
{
strcpy(this->CaseID ,NewCaseID);
}
char* CCase::GetCaseName()
{
return this->CaseName ;
}
void CCase::SetCaseName(char NewCaseName[20])
{
strcpy(this->CaseName ,NewCaseName);
}
int CCase::GetConsultationCount()
{
return this->ConsultationCount ;
}
void CCase::SetConsultationCount(int NewConsultationCount)
{
this->ConsultationCount =NewConsultationCount;
}
CCase::~CCase()
{
}
*************************************************************
//MyServer.cpp::InitInstance()
:
:
:
if (!ProcessShellCommand(cmdInfo))
return FALSE;
CSocket ServerSocket;
BOOL Created;
BOOL ListenStatus;
int nConnectionBacklog=5;
BOOL AcceptClientRequestStatus;
Created=ServerSocket.Create (20248,SOCK_STREAM,"200.200.200.44");
if(Created==FALSE)
{
AfxMessageBox("Could NOT Create ServerSocket!!!");
return FALSE;
}
AfxMessageBox("Successfully Created ServerSocket!!!");
ListenStatus=ServerSocket.Listen (nConnectionBacklog);
if(ListenStatus==FALSE)
{
AfxMessageBox("Unable To Listen On Port!!!");
return FALSE;
}
AfxMessageBox("Listening On Port 20248!!!");
CSocket ReceiveRequestSocket;
AfxMessageBox("Successfully Constructed Socket For Receiving Client Requests!!!");
AcceptClientRequestStatus=ServerSocket.Accept (ReceiveRequestSocket);
if(AcceptClientRequestStatus==FALSE)
{
AfxMessageBox("Could NOT Accept Client Connections!!!");
return FALSE;
}
AfxMessageBox("Successfully Accepting Client Requests!!!");
CSocketFile file(&ReceiveRequestSocket);
AfxMessageBox("Successfully Constructed File For Storing/Loading Client Requests!!!");
CArchive arIn(&file,CArchive::load);
AfxMessageBox("Successfully Constructed Archive Object For Loading The Socket File!!!");
CArchive arOut(&file,CArchive::store);
AfxMessageBox("Successfully Constructed Archive Object For Storing The Socket File!!!");
CCase theCase;
CCase *pCase;
theCase.SetCaseID ("CASE1");
theCase.SetCaseName ("STOMACACHE");
theCase.SetConsultationCount (10);
arOut.WriteObject((CObject*)&theCase);
AfxMessageBox("Case Object Sent!!!");
arOut.Close();
pCase=(CCase*)arIn.ReadObject(RUNTIME_CLASS(CCase));
AfxMessageBox("Case Object Received!!!");
// The one and only window has been initialized, so show and update it.
m_pMainWnd->ShowWindow(SW_SHOW);
m_pMainWnd->UpdateWindow();
return TRUE;
*************************************************************
//MyClient.cpp::InitInstance()
:
:
:
if (!ProcessShellCommand(cmdInfo))
return FALSE;
// The one and only window has been initialized, so show and update it.
CSocket ClientSocket;
BOOL Created;
BOOL Connected;
Created=ClientSocket.Create();
if(Created==TRUE)
{
AfxMessageBox("Client Socket Created!!!");
}
Connected=ClientSocket.Connect ("200.200.200.44",20248);
if(Connected==TRUE)
{
AfxMessageBox("Connection Established With The Server!!!");
}
CSocketFile file(&ClientSocket);
CArchive OB_IN(&file,CArchive::load );
CArchive OB_OUT(&file,CArchive::store);
CCase theCase;
CCase *pCase;
OB_OUT.WriteObject((CObject*)&theCase);
AfxMessageBox("Case Object Sent!!!");
pCase=(CCase*)OB_IN.ReadObject(RUNTIME_CLASS(CCase));
AfxMessageBox("Case Object Received!!!");
AfxMessageBox(pCase->GetCaseID());
AfxMessageBox(pCase->GetCaseName());
m_pMainWnd->ShowWindow(SW_SHOW);
m_pMainWnd->UpdateWindow();
return TRUE;
*************************************************************
Thanking You Very Much!!!
Warm Regards,
G.V.Bhaskar
|
|
|
|
|
Dear Friends,
I would like To Send my "Case" Object From One Client To Any Other Clients (whom I would Target To) Through My Server.The Server is to be Multithreaded.I would like to Use CSocketFile Class to make the Transfer from Client To Server And Then ,from Server To Other Client(s).
I am Presenting My "Case" Class , to enable you to help me better.I would like to know which Classes I need To Build and where.I am very new to Socket Programming,I need the Architecture.
Class CCase
{
protected:
char CaseID[10];
char CaseName[20];
int ConsultationCount;
public:
char* GetCaseID();
void SetCaseID(char NewCaseID[10]);
char* GetCaseName();
void SetCaseName(char NewCaseName[20]);
int GetConsultationCount();
void SetConsultationCount(int NewConsultationCount);
};
Also, Apart From the Above declarations,my Case Class Also Contains some objects (of Other Classes,I used) as members.
Just Have A Look At My Code :
*************************************************************
//Case.cpp
IMPLEMENT_SERIAL (CCase,CObject,1)
void CCase::Serialize(CArchive& ar)
{
CObject::Serialize (ar);
if(ar.IsStoring ())
{
ar.Read (this->CaseID ,20);
ar.Read (this->CaseName,20);
ar.Read ((void*)this->ConsultationCount,100) ;
ar.Flush ();
}
else if(ar.IsLoading())
{
ar.Write (this->CaseID,20 );
ar.Write(this->CaseName ,20);
ar.Write ((void*)this->ConsultationCount,100 );
ar.Flush ();
}
}
char* CCase::GetCaseID()
{
return this->CaseID ;
}
void CCase::SetCaseID(char NewCaseID[10])
{
strcpy(this->CaseID ,NewCaseID);
}
char* CCase::GetCaseName()
{
return this->CaseName ;
}
void CCase::SetCaseName(char NewCaseName[20])
{
strcpy(this->CaseName ,NewCaseName);
}
int CCase::GetConsultationCount()
{
return this->ConsultationCount ;
}
void CCase::SetConsultationCount(int NewConsultationCount)
{
this->ConsultationCount =NewConsultationCount;
}
CCase::~CCase()
{
}
*************************************************************
//MyServer.cpp::InitInstance()
:
:
:
if (!ProcessShellCommand(cmdInfo))
return FALSE;
CSocket ServerSocket;
BOOL Created;
BOOL ListenStatus;
int nConnectionBacklog=5;
BOOL AcceptClientRequestStatus;
Created=ServerSocket.Create (20248,SOCK_STREAM,"200.200.200.44");
if(Created==FALSE)
{
AfxMessageBox("Could NOT Create ServerSocket!!!");
return FALSE;
}
AfxMessageBox("Successfully Created ServerSocket!!!");
ListenStatus=ServerSocket.Listen (nConnectionBacklog);
if(ListenStatus==FALSE)
{
AfxMessageBox("Unable To Listen On Port!!!");
return FALSE;
}
AfxMessageBox("Listening On Port 20248!!!");
CSocket ReceiveRequestSocket;
AfxMessageBox("Successfully Constructed Socket For Receiving Client Requests!!!");
AcceptClientRequestStatus=ServerSocket.Accept (ReceiveRequestSocket);
if(AcceptClientRequestStatus==FALSE)
{
AfxMessageBox("Could NOT Accept Client Connections!!!");
return FALSE;
}
AfxMessageBox("Successfully Accepting Client Requests!!!");
CSocketFile file(&ReceiveRequestSocket);
AfxMessageBox("Successfully Constructed File For Storing/Loading Client Requests!!!");
CArchive arIn(&file,CArchive::load);
AfxMessageBox("Successfully Constructed Archive Object For Loading The Socket File!!!");
CArchive arOut(&file,CArchive::store);
AfxMessageBox("Successfully Constructed Archive Object For Storing The Socket File!!!");
CCase theCase;
CCase *pCase;
theCase.SetCaseID ("CASE1");
theCase.SetCaseName ("STOMACACHE");
theCase.SetConsultationCount (10);
arOut.WriteObject((CObject*)&theCase);
AfxMessageBox("Case Object Sent!!!");
arOut.Close();
pCase=(CCase*)arIn.ReadObject(RUNTIME_CLASS(CCase));
AfxMessageBox("Case Object Received!!!");
// The one and only window has been initialized, so show and update it.
m_pMainWnd->ShowWindow(SW_SHOW);
m_pMainWnd->UpdateWindow();
return TRUE;
*************************************************************
//MyClient.cpp::InitInstance()
:
:
:
if (!ProcessShellCommand(cmdInfo))
return FALSE;
// The one and only window has been initialized, so show and update it.
CSocket ClientSocket;
BOOL Created;
BOOL Connected;
Created=ClientSocket.Create();
if(Created==TRUE)
{
AfxMessageBox("Client Socket Created!!!");
}
Connected=ClientSocket.Connect ("200.200.200.44",20248);
if(Connected==TRUE)
{
AfxMessageBox("Connection Established With The Server!!!");
}
CSocketFile file(&ClientSocket);
CArchive OB_IN(&file,CArchive::load );
CArchive OB_OUT(&file,CArchive::store);
CCase theCase;
CCase *pCase;
OB_OUT.WriteObject((CObject*)&theCase);
AfxMessageBox("Case Object Sent!!!");
pCase=(CCase*)OB_IN.ReadObject(RUNTIME_CLASS(CCase));
AfxMessageBox("Case Object Received!!!");
AfxMessageBox(pCase->GetCaseID());
AfxMessageBox(pCase->GetCaseName());
m_pMainWnd->ShowWindow(SW_SHOW);
m_pMainWnd->UpdateWindow();
return TRUE;
*************************************************************
Thanking You Very Much!!!
Warm Regards,
G.V.Bhaskar
|
|
|
|
|
Hi there,
To allow the server app to forward received objects to other clients, you first need
to expand your server to allow multiple clients to connect. Just call ServerSocket.Accept() in a loop and store the returned CSocket (or derived) objects, one for each connected client, somewhere (you could use a CList for this).
I guess the easiest way to handle client requests is to derive a class from CSocket and pass instances of these objects to Accept(). By overriding the OnReceive() method (see CSocket's base class CAsyncSocket in the online docs), you can cause code to be executed then data is received from a client. Just receive the object like you did in your example and forward it to all other connected clients using the socket objects you stored.
You should also override the OnClose() method to remove socket objects from the socket list if the connection is being closed.
As an aside, you could change your CaseId and CaseName member variables of CCase to CStrings, which allows you to (de)serialise them using the << and >> operators, ie.
ar << CaseID << CaseName << ConsultationCount;
Hope this helps (and works )
Alwin
|
|
|
|
|
I need some information about the Media Player control (msdxm.ocx) which is about to be embedded in a MFC application.
Where should i look for it?
rechi
|
|
|
|
|
I believe that's related to DirectShow in MSDN.
|
|
|
|
|
Hi Ive got through those errors and made me files.
both named here
test.h
test1.h
Now I got everything ready i think. I tried to compile it, but it says this
[b]Cannot Compile the file 'C:\Windows\Desktop\Orbiternew\Orbitersdk\include/test.h';no compile tool is associated with the file extention.[/b]
Thats what it says, now i think i know im so close to compiling this file, andI would really like to finish it, can anyone please tell me what this means?
Thanks!
Kevin
================================================== I'm Almost ready to make my DLL, woohoo!
==================================================
|
|
|
|
|
You can't compile a header file, only a .cpp file. You can compile a project which includes a class all in a .h file, but not a .h file by itself.
Christian
The tragedy of cyberspace - that so much can travel so far, and yet mean so little.
And you don't spend much time with the opposite sex working day and night, unless the pizza delivery person happens to be young, cute, single and female. I can assure you, I've consumed more than a programmer's allotment of pizza, and these conditions have never aligned. - Christopher Duncan - 18/04/2002
|
|
|
|
|
I was just wondering if there is an easy way of adding a tool bar in a dialog based Visual C++ program. I am wanting to code an FTP file browser program. Well not exactly an FTP file browser, but that is the only program that has already been produced by other people that I can compare it to so that you could possibly help me a bit.
Now from what I have seen of an SDI or MDI is that it would not be that suitable to what I am wanting to achieve. But the dialog based approach seems to be able to do everything that I will be needing, apart from a tool bar that I have found. Or maybe I am wrong and an SDI or MDI approach would be more suitable. Any help would be appreciated. Thanks
|
|
|
|
|
|
Hi,
my camera doesn't work with VidCap32 . It says
Device not properly installed.. What do i do..
Can i use Directx for taking a Shot from my
PC Camera.. Please help
I have to develop an app. to capture a shot from
my PC Camera (LG LPC-UC35)
Sameer
|
|
|
|
|
Hello!
I have a class called Process and each object of class project has two integer private data member variables:
priority and processID
I want to create a priority queue from the STL made up of Prcoess objects. How do I sort them according to their priority data member? I have a function called getPriority that all it does is 'return priority' of the object.
typedef priority_queue< Process, greater<process> > aQueue;
|
|
|
|
|
Overload the operator< function for your class. This function should calculate the result based on the priority member of your class.
Build a man a fire, and he will be warm for a day Light a man on fire, and he will be warm for the rest of his life!
|
|
|
|
|
This is the code to display my fakemenu:
BOOL CXPMenu::ShowMenu(int nOrient,BOOL bFromKey, int x, int y,/*HWND pParentW*/CWnd* pParent, HMENU hMenu)
{
ASSERT(hMenu);
//pParent->m_hWnd=pParentW;
HideMenu();
//m_pToolbar=pToolbar;
m_pMenu->m_hMenu = hMenu;
mmenu = m_pMenu;
m_pParent=pParent;
m_nSelectedItem=-1;
//m_bMouseInMenu=FALSE;
//m_nOrient=nOrient;
CString strClassName = ::AfxRegisterWndClass (
CS_SAVEBITS,
::LoadCursor(NULL, IDC_ARROW),
(HBRUSH)(COLOR_BTNFACE + 1), NULL);
DWORD dwStyle = WS_POPUP;
PlayPopupSound();
if(!CreateEx(0,AfxRegisterWndClass(CS_SAVEBITS,LoadCursor(NULL,IDC_ARROW),(HBRUSH)CBrush(GetSysColor(COLOR_BTNFACE))),NULL,WS_POPUP,x,y,100,100,*pParent,0))
// if (!CreateEx(0,strClassName,NULL,dwStyle,CRect(x,y,100,100),pParent))
{
return FALSE;
}
m_pParent->SendMessage(WM_ENTERMENULOOP,FALSE);
SetCapture();
int cx=0,cy=0,n;
CSize siz;
CRect rect;
CDC& dc=*GetDC();
// Revised by Zhenxin Li.
// Change the font to the default menu's font.
dc.SelectObject((HFONT)GetStockObject(DEFAULT_GUI_FONT));
// dc.SelectObject(m_pToolbar->GetFont());
GetClientRect(rect);
CString tmp;
LPCTSTR q;
cy=4;
m_rectItem.SetSize(0);
m_accelList.SetSize(0);
for(n=0; n < (int)m_pMenu->GetMenuItemCount(); n++)
{
m_pMenu->GetMenuString(n,tmp,MF_BYPOSITION);
//DrawMenuItem(n,dc,m_rectItem[n],FALSE,TRUE);
for(q=tmp; *q; q++)
{
//CString str(_T("Test"));
//dc.DrawText(str,m_rectItem[n],DT_LEFT|DT_SINGLELINE);
if(*q=='&')
{
int s=m_accelList.GetSize();
m_accelList.SetSize(s+1);
m_accelList[s].nKey=toupper(*(q+1));
m_accelList[s].nId=m_pMenu->GetMenuItemID(n);
break;
}
}
siz=DrawMenuItem(n,dc,rect,FALSE,FALSE);
m_rectItem.Add(CRect(4,cy,0,cy+siz.cy-1));
if(siz.cx>cx) cx=siz.cx;
cy+=siz.cy;
}
cy+=4;
cx+=8;
ReleaseDC(&dc);
for(n=0; n<m_rectitem.getsize(); n++)
="" m_rectitem[n].right="cx-4;
/*" if(m_norient="=POP_MENU_RIGHT)" x-="cx;
" else="" y-="cy;
" int="" ncount="(int)m_pMenu-">GetMenuItemCount();
*/
MoveWindow(x,y,cx,cy);
ShowWindow(SW_SHOWNOACTIVATE);
//SetFocus(); // Must have focus to get keyboard events
if(bFromKey) m_nSelectedItem=0;
return TRUE;
}
and after this i call the OnPaint() but..
void CXPMenu::OnPaint()
{
------
int nMenu = m_pMenu->GetMenuItemCount();
for( int p = 0; p < nMenu; p++)
DrawMenuItem(p,dc,m_rectItem[p],FALSE,TRUE);
if(m_nSelectedItem!=-1)
DrawMenuItem(m_nSelectedItem,dc,m_rectItem[m_nSelectedItem],TRUE,TRUE);
}
when i call the GetMenuItemCouny() i can't get the number of items, this is why the menu information is not saved, see the first code, in the firs line appear:
m_pMenu->m_hMenu = hMenu;
where the hMenu is the menu that is chose with this command
ShowMenu(0,0,int x,int y,CWnd* pParent, HMENU hMenu)
wht's wrong with this?
|
|
|
|
|
I used
hhook = SetWindowsHookEx(WH_MOUSE,MyHookProc,MyDLL,NULL);
but It's response only mouse over my app and nothing when outside
hhook,MyHookProc,MyDLL != NULL
Something wrong in my dll ?
Please Help me
Thank you so much
|
|
|
|
|
Window messages are forwarded to the window which contains the mouse hotspot, even though your application has focus. To partially override this behaviour, use the SetCapture() function. That way, if the left mouse button is down, mouse messages are forwarded to the windows that asked for the capture.
|
|
|
|
|
Hi,
Make sure you have the hook in a DLL.
Regards
Sameer
|
|
|
|
|
Yes. My dll have MouseProc (Named MyHookProc)
that I mention it above (hhook,MyHookProc,MyDLL != NULL)
and MyHookProc receive message when mouse over my app only instead of receive mouse message everywhere that it's gone.
Please help me
thank a lot
|
|
|
|
|
The problem is probably in your hookproc. The following hookproc code will emit a beep anytime the right mouse button is clicked.
if (nCode != HC_NOREMOVE
&& (wParam == WM_RBUTTONDOWN || wParam == WM_NCRBUTTONDOWN))
{
MessageBeep(1);
return (1);
}
return CallNextHookEx(ghKeyHook, nCode, wParam, lParam);
Cheers,
Tom Archer
Author, Inside C#
A total abstainer is one who abstains from everything but abstention, and especially from inactivity in the affairs of others.
|
|
|
|
|
No. Code in my MouseProc just increase count number only.
so when MouseProc receive mouse message it will increase it.
when my app run I use keyboard for control it only.
if my mouse over my app . my count is increase (MouseProc receive mouse message) but outside is not.
why ?
Please help me
thank you so much
|
|
|
|
|
I tested the code I posted so it should work for you. However, without seeing your code I (or anyone else) can't do anything but guess. Post the code for the mouseproc, the function that calls SetWindowHookEx and any global/shared variables so that we can see what's going on.
Cheers,
Tom Archer
Author, Inside C#
A total abstainer is one who abstains from everything but abstention, and especially from inactivity in the affairs of others.
|
|
|
|
|
My guess is that your variables are local to the dll, so each dll has a copy of counter and is incrementing it's own. You need to have a shared data segment. You also need this to share the global HHOOK value since every copy of the dll that is loaded needs to use the same value. I don't remember off the top of my head how to do this. I do remember it has to be in a section that all variables are initialized.
Joel Lucsy (jjlucsy@ameritech.net)
|
|
|
|
|
Hi I try to compile my project and it says this?
I dont know what it means. i guess the windows.h file or something, but i dont get it?
Can someone please help me
Thanksompiling...
DeltaGlider.cpp
c:\windows\desktop\orbiternew\orbitersdk\include\orbitersdk.h(12) : fatal error C1083: Cannot open include file: 'windows.h': No such file or directory
Error executing cl.exe.
DeltaGlider.obj - 1 error(s), 0 warning(s)
thats what i get.
Kevin
Im just learning! What can I say?
|
|
|
|
|
My guess is that instead of <windows.h> you have used "windows.h".
Replace the "s with the angle brackets
Nish
Check out last week's Code Project posting stats presentation from :-
http://www.busterboy.org/codeproject/
Feel free to make your comments.
|
|
|
|
|
I trying to make my app run idle in the taskbar. When I look at the Task Manager my program always has 99% of the CPU. Yet other programs (like Windows Messanger or my virus scanner) sit at 0%. Do I need to mess with the priority? Can I some how cut out the message loop? Any information would be appriciated.
Thanks,
Chris
|
|
|
|
|
Your app is obviously working. Figure out what it is doing, stop it, and it will be idle.
Christian
The tragedy of cyberspace - that so much can travel so far, and yet mean so little.
And you don't spend much time with the opposite sex working day and night, unless the pizza delivery person happens to be young, cute, single and female. I can assure you, I've consumed more than a programmer's allotment of pizza, and these conditions have never aligned. - Christopher Duncan - 18/04/2002
|
|
|
|
|