|
zoopp wrote: Q1: Do i use FD_WRITE to communicate with the client application?
Maybe, but you don't have to use it. If you are sending (a lot of) data you might be interested in this event. It is used for handling partial sends, that is if you send more data then the socket can push over the network at a given time.
zoopp wrote: Q2: FD_WRITE is triggered when the network buffer becomes full.
No, the opposite. If is triggered when the socket can be written to again (after a send with WSAEWOULDBLOCK ), it tells you that the socket is ready to send more data. This is a simplified answer, it is also triggered in other cases, for the full documentation see MSDN[^]
zoopp wrote: Q3: In order to fill it up I should make continuous calls to send() until i receive WSAEWOULDBLOCK.
Yes, until that happens or you have sent all your data. Data will be copied in the socket's send buffer first, the WSAEWOULDBLOCK case only arises if you pump in data faster than the socket can handle (lot of data or slow connection).
zoopp wrote: Q3: Should i use the FD_READ event to send a response based on the data received from the client?
Maybe, you use this event instead of constantly polling the socket "is there more data for me? are there more bytes?". This event is triggered when the socket can be read, it tells you that the socket has more data.
For further reading have a look at examples, e.g. Winsock FAQ[^] (asynchronous sockets). Btw, I tried to simplify the answers... there is much more to talk about when it comes to efficient networking strategies.
Hope this helps and happy coding.
/M
|
|
|
|
|
Thank you for your reply. It made things clearer now.
I'll ask another question if that's ok. You said that FD_WRITE is used for handling partial sends but, according to MSDN, it will also trigger after a call to connect() or accept() . The event for these calls should be handled different than partial sends and the way I'd handle both situation would be by disabling FD_WRITE before accept() /connect() , enabling it back after and by moving the code that was supposed execute in FD_WRITE when a new client connects in the FD_ACCEPT event.
Is this a good way of doing it?
|
|
|
|
|
zoopp wrote: You said that FD_WRITE is used for handling partial sends but, according to MSDN, it will also trigger after a call to connect() or accept().
MSDN can be misleading, you can use it as a reference but it's an epic fail as a tutorial! The FD_WRITE event will also be fired once a client connects. You can interpret it as a "now it is the first time to send data", but it must not be confused with e.g. FD_CONNECT which signals when a client is connected. Check MSDN[^] where it says "Here is a summary of events and conditions for each asynchronous notification message", it describes the different meanings each event may have. Here is a simplified overview of the corresponding events:
* FD_READ informs when (more) data can be received
* FD_WRITE informs when (more) data can be send
* FD_ACCEPT informs when incoming socket is waiting at listening socket, server side only
* FD_CONNECT informs when socket has been connected or attempt failed, client side only
Okay, to answer your question, I would not disable FD_WRITE before connecting and instead let the application logic decide how it handles the event (you can always ignore it when there is no data to be sent). Let me suggest two more things, have a look at Effective TCP/IP Programming: 44 Tips to Improve Your Network Programs[^] (really can recommend to buy it) and maybe join the webchat in the link below.
Hope this helps
/M
|
|
|
|
|
Hi
Is there any algorithm to check if a binary tree
(not BST,just a binary tree with max two childs for each parent)
is AVL tree?
Regards
|
|
|
|
|
Cannot you use the AVL tree definition, i.e. compute the balance factor(s)?
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]
|
|
|
|
|
Can you write some urls with code?
This information is not enough for me
Regards
|
|
|
|
|
Cowork wrote: Can you write some urls with code?
Nope.
Cowork wrote: This information is not enough for me
That is a shame: the AVL definition (and some way to traverse the tree) in my opinion is enough.
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]
|
|
|
|
|
|
Hi,
I would like to know whether there is any library for regular expression to use in c win32 api.
I am using Dev C++ IDE to develop windows programs (not applications). It is time to change to vc 6.0 for win32 api programming. anyway... even if it could be for vc 6.0 then that would also holds good. ?
Today's Beautiful Moments are
Tomorrow's Beautiful Memories
|
|
|
|
|
ATL contains an implementation called CAtlRegExp. It's a little awkward to use, though. The late Paul DiLascia created an excellent wrapper called CRegex (naturally enough). It's part of PixieLib and can be found on his web site[^].
[Edit]
Update - CAtlRegExp is no longer part of the core ATL distribution, but is included in the ATL server classes package. It can be found here[^]. The regex class is in atlrx.h.
[/Edit]
L u n a t i c F r i n g e
|
|
|
|
|
Thank you for the reply. I am new to this env so it would take some time to use it.
Today's Beautiful Moments are
Tomorrow's Beautiful Memories
|
|
|
|
|
You should probably go with the TR1 implementation mentioned below; it'll be less likely to be deprecated.
L u n a t i c F r i n g e
|
|
|
|
|
Yeah. i have to. thank you.
Today's Beautiful Moments are
Tomorrow's Beautiful Memories
|
|
|
|
|
Boost[^] contains a regular expression library called Regex.
The advantage of using this is that Regex is also part of TR1[^], so that it will be part of the C++ standard in the future and will be included as part of the standard library in upcoming C++ compilers (it was include in the April 2008 Visual Studio 2008 Feature Pack and I believe that gcc 4.0 supports it as well).
Graham
Librarians rule, Ook!
|
|
|
|
|
If you are using VC++ 2008 (or even 2005 with the feature pack), you already have TR1 regex installed. Here is a small tutorial.[^]
|
|
|
|
|
Thank you for all the above replies... this it totally new so it would take some time for me to ...
Today's Beautiful Moments are
Tomorrow's Beautiful Memories
|
|
|
|
|
I am trying to write a triple vector to a file and then read the file back into the triple vector. When I try to read the file back after its been saved the first fifty values come out correct but the rest of the values are garbage. I'd be really appreciative if someone could help me out here. Thanks a lot!
File declaration:
fstream memory_file("C:\\Users\\Amichai\\Pictures\\output.txt", ios::in | ios::out);
The write function:
void save_training_data(fstream &memory_file, vector<vector<vector<long double> > > &training_data)
{
int sizeI = training_data.size();
memory_file.write((const char *)&sizeI, sizeof(int));
for (int i=0; i < sizeI; i++)
{
int sizeJ = training_data[i].size();
memory_file.write((const char *)&sizeJ, sizeof(int));
for (int j=0; j < sizeJ; j++)
{
int sizeK = training_data[i][j].size();
memory_file.write((const char *)&sizeK, sizeof(int));
for (int k = 0; k < sizeK; k++)
{
int temp;
temp = (int)training_data[i][j][k];
memory_file.write((const char *)&temp, sizeof(int));
}
}
}
}
The read function:
void upload_memory(fstream &memory_file, vector<vector<vector<long double> > > &training_data)
{
memory_file.seekg(ios::beg);
int temp=0;
int sizeK, sizeJ, sizeI;
memory_file.read((char*)&sizeI, sizeof(int));
training_data.resize(sizeI);
for (int i=0; i < sizeI; i++)
{
memory_file.read((char*)&sizeJ, sizeof(int));
training_data[i].resize(sizeJ);
for (int j=0; j < sizeJ; j++)
{
memory_file.read((char*)&sizeK, sizeof(int));
training_data[i][j].resize(sizeK);
for (int k = 0; k < sizeK; k++)
{
memory_file.read((char*)&temp, sizeof(int));
training_data[i][j][k]=temp;
}
}
}
}
Thanks again,
Amichai
|
|
|
|
|
Just solved the problem.
The file declaration needs the ios::binary specification.
|
|
|
|
|
5 for self-solved and posting the solution
Regards.
--------
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?
Help me to understand what I'm saying, and I'll explain it better to you
Rating helpfull answers is nice, but saying thanks can be even nicer.
|
|
|
|
|
Hi
I need declare a wchar_t array which should looks like:
strarray[1] = "ddgfdgd";
strarray[2] = "ddgfdgd ... sada";
...
strarray[n] = "ddgfdgd";
The "n" is variable.
wchar_t** strarray= new wchar_t[n][];
is not correct.
Any suggestion?
|
|
|
|
|
You need to allocate pointers to wchar_t like so:
wchar_t** strarray = new wchar_t*[n];
I tend to use the Windows types for character pointers like so:
LPWSTR* strarray = new LPWSTR[n];
[edit]Add ref to LPWSTR[/edit]
|
|
|
|
|
While Richard has answered your query, you'll be much better off using an array of std::string objects (that is - if you don't want to use something like a vector ). This means no hand crafted memory allocation or management, plus no dangling pointers or other pointer related failure modes waiting to crash your application.
“Follow your bliss.” – Joseph Campbell
|
|
|
|
|
A std::wstring in his case
|
|
|
|
|
Ah, the joys of being a nitpick.
OT: How's married life? Probably too early to comment?
“Follow your bliss.” – Joseph Campbell
|
|
|
|
|
Rajesh R Subramanian wrote: Ah, the joys of being a nitpick.
Rajesh R Subramanian wrote: OT: How's married life? Probably too early to comment?
Honnestly, there's not much differences... We were already living together for 3 years so, not much of a change.
|
|
|
|