|
Hi there,
it is possible to use connected UDP sockets, however the information you get is limited. Using connect on a UDP socket (it will not cause any network traffic) together with send (instead of the usual sendto ) allows you to get asynchronous error information... e.g. 'connection refused' if the target peer is not listening on given UDP port. It is pretty much limited to that. I am not sure what kind of "connection problems" you wish to detect, but UDP is not very reliable and if you want to make sure that no data is lost or recover from temporary network outages you need to write your own protocol to detect/correct such cases. As a short note, TCP provides this and more for free.
/M
|
|
|
|
|
Thanks for the reply,
The problem is that we have some wireless mobile devices that are talking to a windows application via UDP sockets using SIM card (GPRS), sometimes the mobile device can not send any message to the application and the application does not know if the socket is down or not! I need to get notified in my application about the network issue (socket disconnection...)
thanks,
|
|
|
|
|
Unfortunately, this information is not provided with UDP.
You need to implement a heart beat (or use an existing library that does it for you). Maybe you can implement a simple solution where the Windows application will mark any mobile device "disconnected" which hasn't sent anything within a time intervall. The next time the mobile device sends something it will be marked "connected" again.
Hope it helps!
|
|
|
|
|
I would like to know the behavior of strlen() when an uninitilized char array is passed as a parameter
char my_str[6];
int len = strlen(my_str);
HKEY hKey;
RegOpenKey(HKEY_LOCAL_MACHINE,"HKEY_LOCAL_MACHINE\\SOFTWARE\\Analog Devices\\SMWDMIF\\Settings",&hKey);
RegQueryValueEx(hKey, "Mode", 0, NULL, (LPBYTE)my_str, &len);
what value would len have when the above code gets executed? Will it cause any compiler/runtime errors?
modified on Wednesday, March 12, 2008 11:33 AM
|
|
|
|
|
still, it searches for the '\0' character.
koumodaki wrote: what value would len have when the above code gets executed?
len = number of character preceeding a '\0' character.
koumodaki wrote: RegQueryValueEx(hKey, "Mode", 0, NULL, (LPBYTE)my_str, &len);
here it expects the buffer size not the string len.
|
|
|
|
|
but '\0' is not present. So how does it know the end of the char array? what value gets stored in len?
|
|
|
|
|
i modified my reply please look at it.
|
|
|
|
|
koumodaki wrote: but '\0' is not present.
It is, just not at the location you desire. For example, if my_str resides at memory address 0x1234, then strlen() will start counting from that locaton until it finds a '\0' character. Use your debugger to see this in action.
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
my_str is actualy buffer to store the registry key data. Since I am using strlen() to ge the buffer size, I wanted to know the side-effects of using the function this way.
Also I have not initilized my_str to any value. As far as I know only memory is alocatd by the compiler when I define the array. So can I safetly assume that the variable len = 6, the size of decalred array?
|
|
|
|
|
koumodaki wrote: Since I am using strlen() to ge the buffer size...
strlen() dos not get the size of anything. Use sizeof instead.
koumodaki wrote: ...I wanted to know the side-effects of using the function this way.
At a minimum, the program won't work.
koumodaki wrote: Also I have not initilized my_str to any value.
But it does get initialized, whether you did it or not.
koumodaki wrote: So can I safetly assume that the variable len = 6, the size of decalred array?
You can, but you'd be wrong.
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
|
koumodaki wrote: Since I am using strlen() to ge the buffer size
buffer size and string len cannot interpretted same.
koumodaki wrote: As far as I know only memory is alocatd by the compiler when I define the array
size of array is the buffer size here.
koumodaki wrote: So can I safetly assume that the variable len = 6, the size of decalred array?
yes, but if your regvalue string length is greater than 5 you won't get the complete string.
|
|
|
|
|
|
koumodaki wrote: I wanted to know the side-effects of using the function this way.
high probability of an Access Violation error, followed by a nasty dialog box and the termination of your application.
|
|
|
|
|
Hi all,
I have developed a dialog based application. In CMyDialog::OnInitDialog() i wrote code to add TrayIcon.
HICON hIcon = NULL;
m_NotifyIconData.cbSize = sizeof(NOTIFYICONDATA);
m_NotifyIconData.hWnd = m_hWnd;
m_NotifyIconData.uID = IDR_MAINFRAME;
m_NotifyIconData.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;
m_NotifyIconData.uCallbackMessage = ID_TRAY_MESSAGE; //WM_USER + 1
hIcon = (HICON) LoadIcon(AfxGetInstanceHandl(),MAKEINTRESOURCE (IDR_MAINFRAME));
m_NotifyIconData.hIcon = hIcon;
strcpy(m_NotifyIconData.szTip, "My Tray Icon");
Shell_NotifyIcon(NIM_ADD, &m_NotifyIconData);
if (hIcon)
DestroyIcon(hIcon);
It successfully added Tray Icon to the Notification area.
My sample application is running well. But, when i kill windows "explorer.exe" process from task manager and start "explorer" again, TrayIcon is missing in Notification area. I want Tray icon to be added again in this scenario. How to do this?
Thank you...
|
|
|
|
|
ramana.g wrote: How to do this?
By reading this article.
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
thank you David
|
|
|
|
|
Hello
Can i get help to count no. of folders in a directory.
|
|
|
|
|
Yes, you may. I have 10 fingers and 10 toes. What are you working with?
I'm going to become rich when I create a device that allows me to punch people in the face over the internet.
"If an Indian asked a programming question in the forest, would it still be urgent?" - John Simmons / outlaw programmer
|
|
|
|
|
You could use FindFirstFile()/FindNextFile() and count only files with the FILE_ATTRIBUTE_DIRECTORY
attribute.
The code could be similar to this[^]
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
int iCountDir=0;
BOOL bWorkingff = Finderff.FindFile("*.*");
bWorkingff = Finderff.FindNextFile();
while(bWorkingff)
{
if (Finderff.IsDirectory()==TRUE)
iCountDir++;
bWorkingff = Finderff.FindNextFile();
}
Finderff.Close()
// iCountDir --Use it now
|
|
|
|
|
|
Hamid. wrote: DlgDirList
does that return no of Directory in the folder?
"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 Friends,
I am looking for RAM Disk Driver for windows. Is it provided by microsoft itself or do I need to write my own ?
|
|
|
|
|
I did a google search for "ram disk 2000".
1st hit was to build your own driver, from microsoft.
3rd hit was a blog descibing various ram disks, with pros and cons.
Iain.
Iain Clarke appears because CPallini still cares.
|
|
|
|