|
Hi,
I don't know if i am in the right forum as my problem seems to be unserstanding of TCP/IP as opposed to MFC
I am using CAsynSocket class to communicate with a server running on a MainFrame
I have my CAsyncSocket object wrapped inside a CWinThread object
In the CWinthread::Initinstance I do CAsyncScoket::Create get a 1 return code to
indicate success
On the MainFrame end I have a Select command looking for connections from the client
Stepping thru the code on Visual Studio after the CAsynSocket::connect I get
a 0 return code the Getsystem error is 10035 (connection not complete)
The (Server) however on the mainFrame detects a connection and issues a subsequent
Accept then is waitting to read information from Windows MFC client
My problem is that the Windows MFC Client CASyncsocket::OnConnect callback function is
never invoked to complete the connection from the client
Any help of someone pointing me to where I can further debug this would be appreciated
Thanks
|
|
|
|
|
The thing I want to point out(just a guess) is that may be because of debugging process your connection is getting lost in the middle. You should check. Try to skip few parts during debugging and check if it returns the proper value
|
|
|
|
|
On the client side... why don't you try using a synchronous socket first? The biggest difference is that all the calls will block until they return but the coding should be simpler... and the asynch and synch sockets are essentially the same internally (within the framework). If the synchronous socket doesn't work, maybe you're doing something else wrong, hard to tell without any code. There could be a number of things wrong.
|
|
|
|
|
Hi,
I am assuming you are refering to CSocket class since it is derived from CAsynSocket
I can call CSocket::connect
it will block unitil connection is complete
|
|
|
|
|
Yeah, that's the difference between the two, one is synchronous and the other is asynchronous.
|
|
|
|
|
Okay
it worked on Create (port,SOCK_STREAM,NULL)
since these options are not on the CSocket version of
FD_READ|FD_WRITE|FD_CONNECT|FD_CLOSE|FD_OOB|FD_ACCEPT I assume they are in effect
The Connect got a "1" so I assumeed it worked
All the overidlable OnSend OnRecieve are in effect except I assume OnConnect
I have to do further testing However it is late here in East Coast US
If I run into another problem I'll start another post
thank you
|
|
|
|
|
How can we determine the phisycal drive where is installed the running operating sistem (windows)?
36. When you surround an army, leave an outlet free.
...
Do not press a desperate foe too hard.
SUN-TZU - Art of War
|
|
|
|
|
GetWindowsDirectory()[^] should help you. It will give you the whole path, but you can find the drive from the path.
"Real men drive manual transmission" - Rajesh.
|
|
|
|
|
GetWindowsDirectory() returns a path like X:\win64. I need to determine what
\\.\PhisycalDriveN hosts the X: partition. Any solution?
36. When you surround an army, leave an outlet free.
...
Do not press a desperate foe too hard.
SUN-TZU - Art of War
|
|
|
|
|
May be this MSDN example [^] is helpful.
|
|
|
|
|
I write an app for media erasure.
It displays via DISK_GEOMETRY and Device IoControl PhisycalDriveX .
It is important not to try erasure on the phisycal device that holds the OS. So, I need to see if the OS that runs is located on a phisycal drive that I intend to erase.
Probably is better to skip that device.
36. When you surround an army, leave an outlet free.
...
Do not press a desperate foe too hard.
SUN-TZU - Art of War
|
|
|
|
|
There is no API function returning the physical devive. You must use GetWindowsDirectory() and then determine the device for the drive letter.
|
|
|
|
|
... and how to determine the device for the drive letter?
36. When you surround an army, leave an outlet free.
...
Do not press a desperate foe too hard.
SUN-TZU - Art of War
|
|
|
|
|
Use the QueryDosDevice[^] function to get the physical device name from the drive name.
Make sure the drive name does not contain the trailing '\' (e.g: use "c:" instead of "c:\\")
This will give you something like \Device\HardDisk0 or whatever is relevant to your machine.
I hope this helps
"It was when I found out I could make mistakes that I knew I was on to something."
-Ornette Coleman
"Philosophy is a study that lets us be unhappy more intelligently."
-Anon.
|
|
|
|
|
See the link from my previous post. It does not contain a ready-to-use solution, but contains enough information to do it yourself.
|
|
|
|
|
You can use the ExpandEnvironmentStrings API with the %SYSTEMDRIVE% environment variable.
|
|
|
|
|
|
I want to set a window position below on listctrl selected item :
BOOL CMyDlg::OnInitDialog()
{
CDialog::OnInitDialog();
SetIcon(m_hIcon, FALSE);
SetWindowPos(NULL, m_nX, m_nY, 0, 0, SWP_NOSIZE | SWP_NOZORDER);
return TRUE; }
and from an form with a list-control, I want to show above dialog right below of selected list-control item :
int nItem = 0;
POSITION pos = m_List.GetFirstSelectedItemPosition();
if(pos)nItem = m_List.GetNextSelectedItem(pos);
CRect rect;
CPoint point;
CMyDlg dlg;
m_List.GetWindowRect(rect);
m_List.GetItemPosition(nItem,&point);
ClientToScreen(&point);
dlg.m_nX = rect.left;
dlg.m_nY = rect.top + point.y;
dlg.DoModal();
still, the CMyDlg dialog does not position right below of selected listcontrol item ...
I didn't find an list-control method to help me out ... can you give me a little ideea ?
Thank you.
|
|
|
|
|
Not sure this will work, but try:
m_List.ClientToScreen(&point);
dlg.m_nX = point.x;
dlg.m_nY = point.y + 10;
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Thank you, I will try but why 10 (point.y + 10) ? It is about list header, in Win7 the list header have a height, in XP another ... anyway, I will try and let you know what I've done ...
|
|
|
|
|
Note the other subtle change he suggested.
m_List.ClientToScreen(&point);
you used "ClientToScreen" in the context of your dialog, he's suggesting doing "ClientToScreen" in the context of the m_List control. He's changing which client's windows coordinate system to interpret the "point".
|
|
|
|
|
I got ideea, and solve the problem. Thank yyou very much !
|
|
|
|
|
Dear all, I have a problem with implementing getter and setter type class in visual C++.
Hope somebody can help me. Let me first explain the detail of my code first.
I have 3 classes separated in .cpp and .h files
- SaveClass.cpp and SaveClass.h
= stores all variable values
- Class2.cpp and Class2.h
= call Set function of "SaveClass" class to set the value
- Class1.cpp and Class1.h
= call Get function of "SaveClass" class to get the value
the codes for three class are as follows:
1. SaveClass.h
class SaveClass
{
public:
SaveClass(void);
~SaveClass(void);
int Get() const;
int Set(int var);
private:
int testVariable;
};
2. SaveClass.cpp
#include "SaveClass.h"
SaveClass::SaveClass(void){testVariable = 1;}
SaveClass::~SaveClass(void){}
int SaveClass::Get() const{return testVariable;}
int SaveClass::Set(int var){
testVariable = var;
return testVariable;
}
3. Class2.h
class Class2
{
public:
Class2(void);
~Class2(void);
int function2(void);
};
4. Class2.cpp
#include "SaveClass.h"
int Class2::function2(void)
{
SaveClass coba;
int setNumber=2;
coba.Set(setNumber);
cout << "Value for Set : " << setNumber << endl;
return 0;
}
5. Class1.h
class Class1
{
public:
Class1(void);
~Class1(void);
void function1();
};
6. Class1.cpp
void Class1::function1()
{
SaveClass coba2;
int values = coba2.Get();
cout << "Value from Get : " << values << endl;
}
when I make new class (4th class) and call function2() and function1(), command window shows:
Value for Set : 2
Value from Get : 1
It suppose to be:
Value for Set : 2
Value from Get : 2
but from the result I got 2 and 1. My question is how can I make it correct (Value for Set : 2 and Value from Get : 2)? Thanks for all your help guys.
|
|
|
|
|
The problem is that you're making the objects of class saveclass as stack variables, meaning they will be deleted when they're out of scope (i.e. at the end of the function where you called them).
You have a couple options:
0. If those two classes are controlled from a single place, you can place your saveclass object there and just pass the pointer to it to the classes that use it. This allows you to have multiple saveclass objects independent of one another.
1. You can make the saveclass storage variables be static, meaning they're independent of instance. If you do this, you can use your calls as you have them in your code, you'll just have to initialize your static variables outside of the class methods.
|
|
|
|
|
Dear Albert, Thank you so much for your help. I chose second option and its working perfectly . I just changed this part below and its working just like I want.
1. SaveClass.h
class SaveClass
{
public:
SaveClass(void);
~SaveClass(void);
int Get() const;
int Set(int var);
};
static int testVariable_static = 1;
2. SaveClass.cpp
int SaveClass::Get() const
{
return testVariable_static;
}
int SaveClass::Set(int var)
{
testVariable_static = var;
return testVariable_static;
}
|
|
|
|