|
First a book recomendation: Effective TCP/IP Programming: 44 Tips to Improve Your Network Programs[^].
TCP is stream oriented. The order of the bytes going in one side always remains the same when it comes out the other side. At the application level there are no packets. Packets come into play after TCP gets your data and transmits it. It is free to do whatever is needed to get the bytes from one place to another -- split, combine, distribute amongst several homing pigeons, whatever. The bytes can arrive on the other side in any order but they are always reassembled in the sending order prior to presentation to the application.
I'm guessing you are sending messages of specific lengths over the socket and most of the time when you do a write on one side, your read on the other side gets the full message in one chunk. This is not always the case. When the receiver does a read(), all of the bytes in the stream may not have arrived yet and you will come up short or bytes from a following message may have arrived and you will get part of the next message. This is normal. You can't prevent it from happening. Assuming there is a one to one coorespondence between reads and writes is a very common mistake. It usually works when you are on the test bench but when things get busy, it all falls apart.
Typically what is done is to add some structure to your messages. Start them with some sort of Start of Message marker followed by the message length. The receiver reads this header portion and then reads again for the indicated length. The read may come up short in which you have to dip in again waiting for additional bytes. Once length bytes have been read, the next read should be for a message header again and the process repeats.
|
|
|
|
|
Thanks for the very helpful reply. This confirms what I had surmised. I'll check out the book too; I've run into many problems along the way that has been quite frustrating. I'm considering a re-write of the server side in Java for it's cross platform compatibility and so I'd like as much information up front during the design phase.
Thanks again.
|
|
|
|
|
Asking this in regard to Having CAsyncSocket run as a seprate thread from My CDialog Thread
If I need a Window/Control/CWnd Class to process notfications
by I just create COntrol/Cdialog Class and not display the Window
thankx
|
|
|
|
|
The base class for the message map architecture is CCmdTarget .
And CWnd is derived from CCmdTarget .
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
So.......... When Include one these macros DECLARE_DYNCREATE and IMPLEMENT_DYNCREATE macros
Is creates that Heirarchy
|
|
|
|
|
ForNow wrote: Is creates that Heirarchy
No, those macros have nothing to do with a class' hierarchy. They are used for serialization, runtime information, and dynamic creation.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"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
|
|
|
|
|
As David said, it has nothing to do with the message map.
These macros are the functionality implemented by the CObject class.
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
Sorry about responding so late as I am Sabbath Observant ??
I read the article that David pointed me to
When I saw the ON_THREAD_MESSAGE and the I noticed PostThreadMessage
I got the IDEA that an app does not need GUI objects to have a message
pump
BTW cann't seemd to find the TCP/IP notification message
for e.g. onSend... would it be WM_SEND I'll look around...
|
|
|
|
|
ForNow wrote: Asking this in regard to Having CAsyncSocket run as a seprate thread from My CDialog Thread
If I need a Window/Control/CWnd Class to process notfications
Have you seen this and this?
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"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
|
|
|
|
|
Thankx for your patience I'll try
Spend more time reading posts before I hit keyboard
|
|
|
|
|
Hi i am to this forum..
I have doubt on Visual C++.How to include the english dictionary .My task is to check whether the entered text is meaningful or not?
Could some one help me out ..
Thanks in advance
|
|
|
|
|
If you find a way to do it, try running your post through the application......
|
|
|
|
|
You're a bad boy.
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]
|
|
|
|
|
The original post is better than most of the posts here.
This signature was proudly tested on animals.
|
|
|
|
|
plz sendz codez......
Here have a and lighten up ....
|
|
|
|
|
This CP article[^] might help you out.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Sakthiprabhu.gs wrote: I have doubt on Visual C++
Don't we all...
Sakthiprabhu.gs wrote: My task is to check whether the entered text is meaningful or not?
What do you mean by entered text? Entered where?
|
|
|
|
|
Sakthiprabhu.gs wrote: My task is to check whether the entered text is meaningful or not?
In terms of spelling or grammar?
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"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
|
|
|
|
|
Sakthi here..Thanks for your good response...
Actually i have check the spelling of word
|
|
|
|
|
WHen ever i send souce code of the application from one system to other system..
In destination system class view is not visible..
please tell me answer if any one know it..
|
|
|
|
|
Does the other system have Visual Studio installed?
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"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
|
|
|
|
|
Hi all...
I'm new to mfc programming, and have a question... hope you can help me
I have a program that make some calculation, the user input some numbers and press a button to start.
When he press the button, the program start the calculations, and shows the results in a Clistbox as it arrives.
The problem is that when I use clistbox.addstring, the results are not automatically show in the clistbox, instead the user have to wait for all calculations to finish to see the results.
What can I do to show the results as soon as it arrives in the clistbox, and continues to do the calculations in the background??
Thx...
|
|
|
|
|
Your UI looks frozen because the message pump is blocked doing calculations. You must do your calculation in a separate thread[^] and post a User defined message[^] to the main window and handle the message to update your list box.
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
Rajesh R Subramanian wrote: You must do your calculation in a separate thread[^] and post a User defined message[^] to the main window
Just an interesting aside - I ran into this a couple of days ago. Rather than define a custom user message for each individual action that must occur on the UI thread, I tried to do it the .NET way - define a single message, say WM_INVOKE, and pass a pointer to a member function as LPARAM when posting the message (like Control.Invoke). Unfortunately, C++ doesn't allow you to take a pointer to a member function of an instance object directly - you can get a pointer to a member function, but you'll have to track the instance yourself and then when calling, use the esoteric .* operator to invoke it.
I couldn't be bothered to write a separate struct to hold the instance pointer and the function pointer, so I ended up writing multiple user defined messages instead
|
|
|
|
|
After you do your addstring, call UpdateWindow:
clistbox.addstring(xxxxx);
clistbox.UpdateWindow();
Good luck.
Karl - WK5M
PP-ASEL-IA (N43CS)
PGP Key: 0xDB02E193
PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193
|
|
|
|