|
The easiest thing to do is tack a header structure (fixed-length) on to each packet you send.
I'll call it MYPACKETHEADER.
On the receive end read sizeof(MYPACKETHEADER) bytes. In that header structure should be a
datalength variable (an int, DWORD, WORD, whatever is appropriate). When you've received
an entire header, read the datalength and now you know how many bytes to read to get the entire
packet.
The way you are doing it now you need to read smaller chunks and parse as you go. Just reading
until there's no more to receive is not good idea (buffer overflow as you mentioned)
Can you post an example of the code you are using to receive from the socket?
Mark
|
|
|
|
|
As mentioned previously TCP provides a stream and you must never rely on data received to be in the same "chunks" as you send them away, you may get multiple chunks at once or possibly only the first bytes of a chunk. In brief this means: collect data coming in and split it up, for example use a text delimiter like a newline between each of your XML strings.
Hope it helps.
/M
|
|
|
|
|
anyone can help me to explain this process step- by- step?
struct list_ele *<br />
sortfun( struct list_ele *list )<br />
{<br />
<br />
int exchange;<br />
struct list_ele *nextp, *thisp, dummy;<br />
<br />
dummy.pointer = list;<br />
do{<br />
exchange = 0;<br />
thisp = &dummy;<br />
while( (nextp = thisp->pointer)<br />
&& nextp->pointer){<br />
if(nextp->data < nextp->pointer->data){<br />
<br />
exchange = 1;<br />
thisp->pointer = nextp->pointer;<br />
nextp->pointer =<br />
thisp->pointer->pointer;<br />
thisp->pointer->pointer = nextp;<br />
}<br />
thisp = thisp->pointer;<br />
}<br />
}while(exchange);<br />
<br />
return(dummy.pointer);<br />
}<br />
~~~@@@###EZRA###@@@~~~
|
|
|
|
|
It's ordering a linked list.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
It is ordering a linked-list using a bubble sort.
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
Q1
We want to store the information about a student. This information includes student’s name, address and roll number. What data type (either built in or user defined) should be used to store all this information in a single variable.
Also we want to store the marks obtained of a student. The marks can be of type integer, character or float. We have to store the student’s marks in a variable of a particular data type. What data type (either built in or user defined) should be used to handle such a wide range of values.
Q2
As we know that in a windows application whenever a key is pressed, a message is sent to the active window. We are developing a DOS based application and want to detect whenever a key is pressed from keyboard. How can we do so?
Q3
We are writing a DOS based application in which we have to display the system date and time. Write down the code for doing so.
Shehwar
|
|
|
|
|
Double posting homework questions isn't likely to get you any answers.
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
A3
int main(int argc, char* argv[]){
char dateStr [9];
char timeStr [9];
_strdate_s( dateStr,9);
_strtime_s( timeStr,9);
//do what you want with variables;
printf("Time is %s date is %s",timeStr,dateStr);
system("pause");
return 0;
}
Cannot advise in other questions..
Sorry!
|
|
|
|
|
Sorry - didn`t read your post carefly - my answer won`t help you...
|
|
|
|
|
Q1 - why did you post this twice ?
Q2 - If someone does this for you, how do you hope to be able to do your next piece of homework ?
Q3 - These questions are really easy, did you sleep in class, lose your text and forget to use google, or would you just be better off doing a different course ?
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
I recommend you make your homework yourself.
|
|
|
|
|
1) We are writing a DOS based application in which we have to display the system date and time. Write down the code for doing so.
2) As we know that in a windows application whenever a key is pressed, a message is sent to the active window. We are developing a DOS based application and want to detect whenever a key is pressed from keyboard. How can we do so?
3)We want to store the information about a student. This information includes student’s name, address and roll number. What data type (either built in or user defined) should be used to store all this information in a single variable.
Also we want to store the marks obtained of a student. The marks can be of type integer, character or float. We have to store the student’s marks in a variable of a particular data type. What data type (either built in or user defined) should be used to handle such a wide range of values.
Dure-shehwar
|
|
|
|
|
Dure-Shehwar wrote: 1) We are writing a DOS based application in which we have to display the system date and time. Write down the code for doing so.
Use the time-related APIs.
Dure-Shehwar wrote: 2) As we know that in a windows application whenever a key is pressed, a message is sent to the active window. We are developing a DOS based application and want to detect whenever a key is pressed from keyboard. How can we do so?
One such way is with getchar() .
Good luck with your homework. Next time, either go to class or don't sleep when you do go. Read #9 here.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
DavidCrow wrote: Good luck with your homework
Nice
|
|
|
|
|
(1)GetSystemTime();
----------------
(2)David Crow answer
---------------
(3)Single variable?
|
|
|
|
|
WhiteSky wrote: GetSystemTime();
In DOS? Are you smoking the good stuff today?
led mike
|
|
|
|
|
I think he needs only to get time/date .
But why smoking
|
|
|
|
|
You've already got a lot of excellent answers.
I made it to "Write down the code for doing so." and stopped. Without a "PLEASE"?
BTW:
Everyone knows to do stuff in DOS you write a Windows program to do the task and call
it from the DOS program.
Enjoy!
|
|
|
|
|
Mark Salsbery wrote: I made it to "Write down the code for doing so." and stopped. Without a "PLEASE"?
He's copying his homework into CP. His teacher didn't say please, so neither did he
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
|
Dear everyone;
I have got a pure C++/ algorithmic question that i would appreciate your input towards.
I have a number of files (lets say 100 files) of similar input formats. To reduce the complexity of the problem I will give you a simplied example:
File 1: File 2: File 3:
A A B
B E A
C D D
D D F
E F E
I want to write a program which produces a tree from the files, in which the first node is the node from the first line (from above) with the highest number of occurences ('A' in this case). Consequently File 3 will be ignored.
The resulting tree will be something like
A (100%)
B (50%) E (50%)
C (50%) D (50%)
D (100%)
E (50%) E (50%)
SO basically the program should go through the files and construct a tree with a % value of each node. every time branching occurs the % will be divided depending on the number of children.
My question is, is there any specific algorithm / similar algorithms which i can use to overcome this problem ? and What's the best way to visualise the tree?
Your help is very much appreciated
Best Regards
llp00na
|
|
|
|
|
llp00na wrote: File 1: File 2: File 3:
A A B
B E A
C D D
D D F
E F E
You've not used alignment correctly (use the <pre> tags) so I'm unclear as to what the three files look like.
llp00na wrote: Consequently File 3 will be ignored.
Why?
llp00na wrote: The resulting tree will be something like
A (100%)
B (50%) E (50%)
C (50%) D (50%)
D (100%)
E (50%) E (50%)
Does this tree branch to the right, or does it branch downward? Again, alignment would make the difference here.
llp00na wrote: SO basically the program should go through the files and construct a tree with a % value of each node. every time branching occurs the % will be divided depending on the number of children.
What exactly does this mean? Use percentages other than 100 and 50 so that we can see how the files relate to the nodes.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
My problem -
I wrote an application that reads com port in a loop and stores received data in log file.
Everything was O.K. , but then i needed to add *.ini file to my app. I`ve constructed a small inifile class to get port settings, etc. from *.ini. Everything works just fine, but, one thing. For example - to define BaudRate i used my inifile class to return int value fo parameter e.g 9600 not CBR_9600.
As i came to StopBits section I realized that ONESTOPBIT is defined as 0 which, which means - I have to store StopBits as its int value - 0. The thing that bothers me is that it`s hard for user to understand - why the hell section StopBits has to be 0, not ONESTOPBIT or 1. Is there any way I could store this value in my config file as string "ONESTOPBIT" and then pass it to DCB as its defined value, without using switch or any other unneeded stuf in my inifile class. Hope somebody will be able to understand what I wrote here..... Please help - I`m stuck on this for whole day already...
|
|
|
|
|
what's wrong with reading in a string, comparing it to a value (or looking it up in a table of
values), and passing on the appropriate integer?
TCHAR szValue[128];
(...read string into szValue from ini/configuration file...)
DWORD dwStopBits;
if (0 == _tcscmp(szValue, _T("ONESTOPBIT"))
dwStopBits = 0;
else
dwStopBits = 1;
>>...without using switch or any other unneeded stuf...
If it makes it easier for the user, is it really unneeded? Sometimes a little code is required
IMO
Mark
|
|
|
|
|
As far as the setting is for StopBits - no problem, but think about what happens, when you want to set baudrate(there are more options available) or, for example pass some GENERIC_READ to CreateFile() e.g. Could this be that there is no way to store DWORD defined variable in *.ini file, and then pass it back to app??
|
|
|
|