|
I have referred to chapter 20 of "teach yourself vc++ + in 21 days by sams " for socket programming using CAsyncSocket class.
I need to understand & implement if the physical connectivity is available or not if "send" command is send. Below is the code snippet.
CString m_strMessage="S";
m_strMessage=m_strMessage+'\x00A';
int iLen = m_strMessage.GetLength();
// Send the message
int iSent = m_sConnectSocket.Send(LPCTSTR(m_strMessage), iLen);
if (iSent == SOCKET_ERROR)
{
AfxMessageBox("Socket Error");
}
else
{
// Sync the variables with the controls
}
It was observed that iSent does not give "SOCKET ERROR" even though Ethernet connection is not available. I need to indicate the user that there is some socket error problem.
I have tried adding below lines of code before send command. But still it does not return correct error code & indicate that the socket connection is not available.
int conn_stat,last_error;
conn_stat= m_sConnectSocket.Connect(m_strName,m_iPort);
last_error= CAsyncSocket::GetLastError();
The last_error remains 0 even if Ethernet cable is removed. Shall I use a timer feature & keep checking if the connection is available or not. If yes, could you help me in achieving this?
|
|
|
|
|
If I'm right you will not get an error because the message was delivered to your networkcard. So create a timer (see Settimer()/Killtimer()) and reset it everytime something is coming in from the server. When the timeout comes close your socket gracefully.
Note: It could be handy to look for the asynchrone versions for sockets. In basis you list all sockets events you are interrested in to a window (see Windows API WSAAsyncSelect()) and it will send you window-messages when that event is actual. With this you will get a window-message stating for example your socket is ready to send...
Good luck
|
|
|
|
|
diptipanchal wrote:
The last_error remains 0 even if Ethernet cable is removed. Shall I use a timer feature & keep checking if the connection is available or not. If yes, could you help me in achieving this?
A TCP socket will not return an error immediately if a network connection is going down. This is by design, if there is a short network outage the connection can recover... on the other side it takes a couple of minutes until an interrupted connection is reported back to the socket (and will be closed with an error).
You can do two things to detect an interrupted connection, such as a removed Ethernet cable:
1) Implement a reasonable fast heartbeat. If peer A wants to know about the status/availability of peer B, it either has to receive a "message" from B in regular intervals (and therfor knows that peer B is alive) -or- when there is no regular traffic to piggyback the heartbeat then one of the peers has to initiate (additional) heartbeats in reasonable intervals. For example an IRC server uses regular ping/pong messages every few minutes to find out about the connection status of its chat clients.
2) Use the IP Helper API[^] to check if your local network interfaces are down.
Hope it helps!
|
|
|
|
|
Hello Sir,
For Ex, if i compressed the tiff file in LZW compression mode, then i opened the compressed image file and view the image information its showing in the compression column LZW ..my doubt is how to modify that text in compression column in image file with out decompression.
Thanks Failure is Success If we learn from it!!
|
|
|
|
|
Hello,
I have tried with CRegistry project from code-project and CVORegistry project from http://www.voscorp.com/products/developer/winmobile/vostring/index.htm[^]. But I am not able to read HKEY_CLASSES_ROOT\CLSID\{D27CDB6E-AE6D-11cf-96B8-444553540000}
I can open till HKEY_CLASSES_ROOT\CLSID but inside it I am not able to open ...
Other Keys and values are working fine I have tried reading those. But I don't know why keys that are in GUID format are not getting open example like {D27CDB6E-AE6D-11cf-96B8-444553540000}
I am sure that key exist I have checked in registry.
Any suggestion.
|
|
|
|
|
The following code works successfully -
::RegOpenKeyEx(HKEY_CLASSES_ROOT, _T("CLSID\\{00020000-0000-0000-C000-000000000046}"), 0, KEY_READ, &hKey);
It will not work if I give KEY_ALL_ACCESS instead of KEY_READ .
The return value says "Access Denied" (5).
For KEY_ALL_ACCESS to work I have to run my program as administrator.
Check the return value of RegOpenKeyEx to determine the cause of failure.
|
|
|
|
|
A Big thanks to you ...
Actually I was getting ErrorCode 3 (Path not found) but I did not checked error-code. Thanks for reminding that.
The problem was with my pc bit version. I am on 64-bit version. So when I searched registry for key
{D27CDB6E-AE6D-11cf-96B8-444553540000}, I found it "Wow6432Node\CLSID\{D27CDB6E-AE6D-11cf-96B8-444553540000}" path.
So I was fetching it as
RegOpenKeyEx(HKEY_CLASSES_ROOT, _T("Wow6432Node\\CLSID\\{D27CDB6E-AE6D-11cf-96B8-444553540000}"), 0, KEY_READ, &m_hkey);
and it was giving path error. While the path is right, I have checked in registry.
but when I removed "Wow6432Node", all worked fine. I think registry/api was redirecting my call.
I was also confused with "(Default)" but I googled out. Now going to test in different pcs and users if all works fine everywhere.
Thanks
Rahul
|
|
|
|
|
Hi
I'm going to make the viewer like "edraw office viewer component" with c++builder2010.
I'd tried to use WordApplication,WordDocument,OleCotainer, but failed.
Do not you have seen the open project or open component like this?
Do you know about "OpenOffice.org"?
Ask for advice...
|
|
|
|
|
what actually you looking for Dude, let your fellow programmer know about your problem "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow Never mind - my own stupidity is the source of every "problem" - Mixture
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
Hai,
I have an application(exe) which makes a report based on some values in an ini file.This ini file is not a static one, we changes the value every 14 days(or over a fixed period of time).If we give our client this exe with the ini file along with it, any time we make changes we hav 2 send the new .ini file to him.But we dont want that. i tried to put the .ini file in the server and given an url for the file & this exe should read from that file.But it nt wrking.Can anybody please Suggest me a solution for this.
Thanks
|
|
|
|
|
Why don't you make your architecture relly client/server. With the client (your application) asking the server for the data?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
One way is as Carlo has suggested.
Alternatively
Your client should download the ini file from URL specified when it starts and use it.
I hope it helps.Regards,
Sandip.
|
|
|
|
|
Can u please tell me how to programatically download a corresponding file from the website.
Thanks,
|
|
|
|
|
Check URLDownloadToFile[^] API. You can also use MFC classes CHttpConnection, CHttpFile. You can also download using WinInet Functions[^]
Search CP for examples.
I hope it helps.Regards,
Sandip.
modified on Monday, March 15, 2010 6:06 AM
|
|
|
|
|
jannathali wrote: Can u please tell me how to programatically download a corresponding file from the website.
why not instead of .Ini file, you save your configuration in XML, it would be easier for you bypass firewall if you use XML, instead .ini, as some firewall block inappropiate filetype to downloaded to your computer. "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow Never mind - my own stupidity is the source of every "problem" - Mixture
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
|
Hi all,
i create this code for some conversion but i dont know waht is the mistake is present dere,
loop is not return,
please chk this code.
Value=72;
digits=7;
CString PDU::Bin(int Value, short digits)
{
CString Bin;
CString result;
short exponent=0;
result = CString("0"[0],32);
do{
if (Value & Power2(exponent)) {
result.Mid(32 - exponent-1, 1);
Value = Value ^ Power2(exponent);
}
exponent += 1;
} while (Value);
if (digits < 0) {
Bin = result.Mid(33 - exponent-1);
} else {
Bin = result.Right(digits);
}
return Bin;
}
int PDU::Power2(int exponent)
{
int Power2=0;
static int res[31+1];
int I;
if( exponent < 0 || exponent > 31)
if(res[0] = 0) {
res[0] = 1;
for(I = 1;I<30;I++) {
res[I] = res[I - 1] * 2;
}
res[31] = 0x80000000;
}
Power2 = res[exponent];
return Power2;
}
please help me.
|
|
|
|
|
Have you already tried
- to build a debug version
- set a breakpoint at the beginning of PDU::Bin(..)
- press F5 to start the Debugger
- and then - just step by F10/F11 to observe the variables evolution
? virtual void BeHappy() = 0;
|
|
|
|
|
The code looks a bit involved what are you trying to do?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
CPallini wrote: what are you trying to do?
Coding "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow Never mind - my own stupidity is the source of every "problem" - Mixture
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
ThatsAlok wrote: Coding
Random Coding.
FFY.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Eddington monkey coding. You measure democracy by the freedom it gives its dissidents, not the freedom it gives its assimilated conformists.
|
|
|
|
|
Le@rner wrote: ...but i dont know waht is the mistake is present dere...
Neither do we. What does the code do? What is it supposed to do? Have you used the debugger to step through the code, observing the various states of Value , res , Bin , and result ?"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
Hi everyone,
I have CERT_CONTEXT with me.
How do I get public key from a digital certificate as HCRYPTKEY to use with API like CryptEncrypt? (ie how to get HCRYPTKEY from CRYPT_BIT_BLOB)
How do I do the same for my private key? (ie how to get HCRYPTKEY from my private key)
Links to C++ examples / documentations are welcome
Thanks in advance.cheers
Varghese Paul
|
|
|
|
|