|
Jip, that is the code that waits for events on the server side. The point is still that every once in a while only the problem occurs that the FD_ACCEPT event is fired after about 30 seconds and though even though it is slow, the connection is then accepted and functions fine onwards.
Cheers
|
|
|
|
|
Hmmm not likely related to the code I've seen so far...
od@ananzi.co.za wrote: and am connecting to 127.0.0.1 or the network ip of 192.168.1.1
If you use "ipconfig" from a command prompt, what's the IP address of your machine?
Is it 192.168.1.1? That's always been my LAN router address.
Can you post the code that builds the sockaddr for both the connect() call on the client and the
bind() call on the server?
I'm not sure why it would be slow only sometimes...the 30 seconds time still says
network/addressing to me...
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
Haven't seen this problem in my networking applications.
Additionally to Mark's comments: The only things I can guess is that your event handling may has a problem -or- your connect call is not IP based and the DNS-resolution for a hostname blocks a while. The server socket should get the FD_ACCEPT practically immediately inside the LAN (<50ms).
|
|
|
|
|
I haven't been able to make any headway as to what the problem/cause is, but some other thoughts ...
Although the application is running on my PC locally, my PC is connected on a nationwide VPN over ADSL. At this stage I am thinking that maybe somehow the routing tables in my tcp/ip stack gets screwed/reset/cleared and that the connection attempt then first "goes out" onto the VPN, before being handled by my application anyway.
I am going to try and snoop the network packets at some stage to try and verify my guess.
Cheers
|
|
|
|
|
Just checking one thing... are you working IP-based or hostname-based in your connect call?
|
|
|
|
|
I have tried both in my connect call, ip and hostname, and both does the slow connect thing without any discernable difference in the frequency of the problem appearing.
|
|
|
|
|
Sorry out of generic ideas, this must not happen! Have a good look at your networking core and try to stress test it isolated from application logic. If it is not a private/research project your are working one I would even consider using an existing network class (CAsyncSocket, IpWorks, etc).
|
|
|
|
|
Hi Moak. I'm out of ideas as well, except that I can now confirm that this problem does not occur when the application are running on a "pure" lan, i.e. no gateways/breakouts/links/etc to our VPN. It is only when I run the applications on PC's that are connected to the VPN that this problem occurs.
But my most technical response to the problem no is: Go Figure !
|
|
|
|
|
Hmmm, sounds like trouble! How about using a different networking library? If you search this forum you will find some suggestions (CAsyncNetwork, IpWorks, etc).
/M
PS: In case you are not sure which to use... feel free to try mine, follow link from my user page and download the SDK
|
|
|
|
|
Err, which link would that be ?
|
|
|
|
|
od@ananzi.co.za wrote: Err, which link would that be ?
sorry for not answering, I was on a holiday. You get a user's page with the "person" icon next to a nickname (here a direct link to mine).
|
|
|
|
|
I am having a problem reading binary files.
Basically, everything works fine as long as the byte I read from the binary file is not a 0x00 byte. For example, reading the following (in hex): A0, 30, C0, C0 ... works fine.
But, reading: A0, 34, 03, 00 ... does not work fine.
When I concatenate the strings, instead of sticking "rec" at the end of "data", it concatenates it BEFORE the end of "data" - I assume this is so because one of the bytes I read (00) is treated like '\0' (null). How do I fix this? I have tried using unsigned chars, but that didn't work, I can't use read with them. The string/char array MUST contain everything I read from the binary file (even 0x00), so it can be like "somebyteshere0x00morebyteshere" which is why i need "rec" added to the END of "data", even if "data" contains nulls before its end.
I am using Visual Studio 2005.
A snippet of my code is posted below
string data = "";
char lr[5];
char rec[1028-4];
...
pageFile.read(lr, 4);
lr[4] = '\0'; // terminate string
...
pageFile.read(rec, length-4); // "length" is extracted from "lr"; it is correct, checked many times
rec[length-4] = '\0'; // terminate string
...
data = lr;
data = data + rec; // <----------- problem happens here
Thanks for any help!
|
|
|
|
|
dfn wrote: I assume this is so because one of the bytes I read (00) is treated like '\0' (null)
it's not just "treated like" a null, it is a null. C-style strings end on zero bytes.
short answer: if your data contains 0's, don't treat it as a C string.
long answer: if you need to read non-text data, you're going to have to read the data into byte arrays (char/u-char) and manipulate it there, with pointers - don't put it in std::strings or CStrings or anything like that because those objects are going to see those 0's and treat them as string terminators.
|
|
|
|
|
Thanks for your help!
I tried strcat on "lr" and "rec" (char arrays), but that resulted in the same thing as adding them to "data" (string).
I couldn't get unsigned chars to work with read().
Every attempt I made, trying to work with chars & strings, or chars only, had the same result.
|
|
|
|
|
dfn wrote: I tried strcat on "lr" and "rec" (char arrays), but that resulted in the same thing as adding them to "data" (string).
right, because binary data is not a string (strcat = string-concatenate).
you are not going to be able to use any function or object that manipulates C-style strings - no "str*" functions, no "string" objects, no *scanf, or *printf functions.
|
|
|
|
|
Ah good ol' for loops.
Thank you very much for your help. I actually learned something
|
|
|
|
|
Are you using Unicode? If so, can you use wstring instead of string ?
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Thanks for the reply.
Not using Unicode, the file is ANSI-encoded.
|
|
|
|
|
you have to write a short function that change all 00 bytes in a so called "string" into the real string "0x00". To do this, read or copy your char array into a unsigned char array that is much longer. then manipulate this unsigned char array (change all 00 bytes into 4 bytes "0x00", then copy the unsigned char array back to your designated string.
|
|
|
|
|
Before I solved it, I was thinking about something like this. Luckily, I solved the problem.
Thanks for the reply!
|
|
|
|
|
Hi,
I have to read a binary file in my projecto too. And then use the values of the binary to complete the names of my elements. I put you a bit of my code, I hope it helps
UINT nObj = 0, nSub = 0;
BYTE byteData = 0x00;
BYTE* pDataBuf;
for (nObj = 0; nObj < Header[6]; nObj++)
{ BYTE aReadSet [8] = {0};
pDataBuf = &aReadSet[0];
for (nSub = 0; nSub < pDoc->m_cmlObjSet[nObj].m_cmlSubSet.GetCount (); nSub ++)
{
file->Read (pDataBuf, 8 * sizeof (BYTE));
aReadSet[0] = *pDataBuf;
CString szNameUnit = "";
szNameUnit.Format (_T("%X"), aReadSet[0]);
pDoc->m_cmlObjSet[nObj].m_cmlSubSet[nSub].m_szSubName = "SubObject"+szNameUnit;
}
}
With that I read every block of data, use the first member of the array (binary ID) to differenciate/identify every element is being saved... The IDs may have values from 00 to FA, and ALL are readen and written correctly.
Ahm... I'm using VC++ 6
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
|
|
|
|
|
Already solved the problem, but appreciate the help! Thanks!
|
|
|
|
|
I have a program where sometimes I need a button to launch a different program.
I used WinExec() for the job, even though I get the impression that it is out of date and I should be using something else. So, first of all, if there is a better choice, please let me know. WinExec() does the job nicely since it is so simple.
Here is my real question. The second application takes a lot of memory and I don't want to launch multiple instances of it. So I would like something to check to see if it is running. If not, launch it. If yes, jump to the instance which is running.
Is there an easy way to do this?
Thanks,
Ilan
|
|
|
|
|
|
IlanTal wrote: I don't want to launch multiple instances of it
See this[^] thread for your question and you said you used of WinExec,its of MSDN :
"This function is provided only for compatibility with 16-bit Windows. Applications should use the CreateProcess function"
|
|
|
|