|
I used a timeout for socket connection. It works like this. But note that this is just an example. There may be typing errors and I am sure it can be wrapped to some funtions.
//1 Create a socket
m_hSocket = ::socket(PF_INET, SOCK_STREAM, 0);
//2 Set time out
struct timeval TimeVal;
TimeVal.tv_sec = iTimeOutSecond;//Pass the time out time here
TimeVal.tv_usec = iTimeOutMicroSecond;
//Try to make socket non-blocking
unsigned long ulNonBlocking = 1;
int iResult = ioctlsocket (m_hSocket,FIONBIO,&ulNonBlocking);//Try to set non-blocking
// connects to peer
int r = ::connect(m_hSocket, (SOCKADDR*)&Peer, sizeof(Peer));
fd_set ReadEvent, WriteEvents, ExceptionEvents;
FD_ZERO (&ReadEvent);
FD_SET (m_hSocket,&ReadEvent);
FD_ZERO (&WriteEvents);
FD_SET (m_hSocket,&WriteEvents);
FD_ZERO (&ExceptionEvents);
FD_SET (m_hSocket,&ExceptionEvents);
int iResult = select (NULL,&ReadEvent,&WriteEvents,&ExceptionEvents,&TimeVal);
if ((iResult == SOCKET_ERROR ) || (iResult == 0) ) //Error or time-out
{
return FALSE;
}
I hope it helps.
www.geocities.com/ton_soft
|
|
|
|
|
Watch out for the use of "select". It has been reported not to be very user-friendly, since it can be a bit tricky - things can happen such as it returning from a ReadEvent and not really being read-ready.
Take a look at http://www.cyberport.com/~tangent/programming/winsock/ (Winsock FAQ).
Cheers,
JFC
|
|
|
|
|
Timeout for what? Remember that, for example, "connect" has it's own timeout...
Can you be more specific as to the way you are using your sockets?
Cheers,
JFC
|
|
|
|
|
I don't know the value of connect timeout ? It's too Long.
Do you how to change this value?
Thanks
|
|
|
|
|
Try using setsockopt API.
|
|
|
|
|
Hi. I need your advice.
I have a large network with the unix-based server (Solaris) and I need to implement some kind of remote administration for this network.
Clients are Win9x, WinNT, Win2k etc...
So I want to use DCOM (cause it's easy to implement in under Win), but what about unix server, that will create these objects on remote machines? Is it easy to work with DCOM under unix (if it is possible) or I must use CORBA (and is it easy to work with CORBA under Win)?
What do you think?
With the best regards, Vitaly.
|
|
|
|
|
It is barely possible to use COM/DCOm on Unix machines but I've never seen it done. It will have to CORBA and God have mercy on your soul.
|
|
|
|
|
Can you try using Microsoft Interix but not sure whether it would work on a w98 m/c
http://www.microsoft.com/windows2000/interix/
I have also heard something on services for unix from Microsoft.
Cheers
Kannan
|
|
|
|
|
<<< In the name of GOD >>>
Hi all.
I want to get ID of object that we are in that(Focus).
For example if i am in Edit Box, this function should return ID of
Edit Box ...
OK ???
Hadi Rezaie
|
|
|
|
|
First you have to get a pointer to the control having input focus. I assume you need the id from the dlg control or parent of all child controls.
//Step 1
static CWnd* CWnd::GetFocus ()
//Step 2
After getting the pointer to the control having input focus call
CWnd::GetDlgCtrlID
this function will return you the window or control identifier value for any child window.
here is an example which can be used from a dlg
CWnd * pWnd = GetFocus ();
int iID = p -> GetDlgCtrlID ();
I hope this helps.
www.geocities.com/ton_soft
|
|
|
|
|
Thanks a looooooot.
Hadi Rezaie
|
|
|
|
|
Hi, Just wondering if anyone can give me some hints on how to
display a pop-up tool tip message when the user moves the mouse
over an instance of a custom class derived from CObject, drawn
within the main window of an SDI app.?
Thanks
|
|
|
|
|
Since your class isn't derived from CWnd, it doesn't receive window messages (like WM_MOUSEENTER, WM_MOUSEMOVE, etc.) Here's a simple-minded solution that
you can quickly implement.
1 Add a bool isPtInObject (CPoint pt) method to your class, which returns
true if pt is contained within the bounds of the object. This method
should be as fast as possible.
2 Override WM_MOUSEMOVE in your view class (SDI/MDI doesn't matter) and
call isPtInObject() for each object contained in the view. If the
method returns true, display the popup window.
You'll need to keep track of the object that caused the previous popup (if
any to be displayed). If that object is not null, it means you need to kill
the previously displayed popup window, if any.
/ravi
"There is always one more bug..."
ravib@ravib.com
www.ravib.com
|
|
|
|
|
Thanks Ravi, I've already implemented the methods to determine when
the cursor is over the objects. I just need to know how to display
the tool tips.
Thanks.
|
|
|
|
|
|
Although I try to be helpful in this forum, in this case I doubt I am medically qualified to assist you....
Christian
The content of this post is not necessarily the opinion of my yadda yadda yadda.
To understand recursion, we must first understand recursion.
|
|
|
|
|
Does any know how to write a cd burning software or have any idea, library to get me start.
SpitFire
|
|
|
|
|
|
Hello,
I'm looking for an easy way to create a virtual directory in IIS via an application written in Visual C++. I know that the Internet Service Manager (HTML version) is using IIS Admin Objects via ADSI, but where can I find some info of how I can use those objects.
Is this method compatible with both IIS 4 and 5? If not what is the best way to go about this?
Best regards,
Philip
|
|
|
|
|
Hi,
I need a simple and small class that I can serialize to disk (using fstream in binary mode). In the class I have a Standard C++ library string member, but after pumping objects of this class to disk I lost the string value on reading back. The class is something like this;
class Person
{
public:
string sName; (private or not doesn't matter)
int nAge;
Person(const string&Name, int nAgeOfPerson);
string GetName() {return sName;};
int GetAge() {return nAge};
}
and the ctor,
Person(const string&Name, int nAgeOfPerson)
{
sName = Name; //tried both, don't work.
sName = Name.substr(); //using initializing list also not!
nAge = nAgeOfPerson;
}
For my class, sizeof tell me the object is alway and only 28 bytes, even when the name is 29 characters long. I have no problem getting the age back. I guess when I write out to the file the name characters were somehow lost. I want to use Standard C++ Lib and using string but I don't know enough .
If I go back the old way using a char szName[50], for example, then everything is OK. But I really don't want to assign 50 bytes for every attribute in the class (small is beautiful for me here). Can someone tell me it is possible to force a value into the string member sName?
I am not sure if I make the point clear. Thanks in advance.
Will
|
|
|
|
|
The problem is that string stores the string you allocated on the heap, not within the class itself. The class only has a pointer to the string, thus when you write the binary contents of the class (including the string) to disk it saves the pointer to string as it exists right now, but when you reload that data, that data doesn't exist anymore, and thus the pointer is pointing off into nowhere.
What you are doing is called "bitwise" persistance, which means it saves the data bit for bit. What you want is called "deep" persistance. And to do this, you have to develop a mechanism to differentiate different types of data in your persistance file.
The easiest way to do this is to store the data as text, using the insertion operators of fstream:
(assumes using namespace std)
void person::opersist(fstream& out)
{
out << sName << endl << nAgeOfPerson << endl;
}
void person::ipersis(fstream& in)
{
in >> sName >> nAgeOfPerson;
}
|
|
|
|
|
i think u r taking in wrong way.
I have to read and write on the contents tab(which appears when u rigth click on any word file and select the properties).i am able to read and write rest all the tabs like (General,Summary,Statstic and custom) but not on contents. I am using IPropertySetStorage. the code i am using is given below please suggest some solution.........
Pankaj Mongia
|
|
|
|
|
Hello,
I created a listbox in a dialog-based application. I already changed (programmatically) the background color of the listbox, and also the text color of its items. But now, I would like to change the highlite color from the default windows color (blue). I would appreciate any help or ideas.
Thank you.
-Jake
|
|
|
|
|
|
Not an easy job. You'll have to create an owner drawn listbox and handle all the drawing and highligting yourself.
|
|
|
|