Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > End line of text based network protocol

Reply
Thread Tools

End line of text based network protocol

 
 
Mike Mimic
Guest
Posts: n/a
 
      05-06-2004
Hi!

I am programming small program which would use its own
text based network protocol. I come to the problem with
ending lines. I was thinking about ending them with \r\n
combination. But the problem is that I would like that
program would be tolerant to other endings (only \r or \n).

So the question is if there is some efficient way to
implement this? Is there some library which would do this?
It should be platform independent.


Mike
 
Reply With Quote
 
 
 
 
Ioannis Vranos
Guest
Posts: n/a
 
      05-07-2004
"Mike Mimic" <> wrote in message
news:c7ehnj$c0n$...
> Hi!
>
> I am programming small program which would use its own
> text based network protocol. I come to the problem with
> ending lines. I was thinking about ending them with \r\n
> combination. But the problem is that I would like that
> program would be tolerant to other endings (only \r or \n).
>
> So the question is if there is some efficient way to
> implement this? Is there some library which would do this?
> It should be platform independent.



Well a check for '\r' detectes both '\r' and '\n' so you could do:

if(c=='\r' || c=='\n')
// ...

The first check detects both '\r' and '\r' '\n' sequence and if none of them
exist checks for '\n' alone.






Regards,

Ioannis Vranos

 
Reply With Quote
 
 
 
 
Mike Mimic
Guest
Posts: n/a
 
      05-07-2004
Hi!

Ioannis Vranos wrote:
Well a check for '\r' detectes both '\r' and '\n' so you could do:
>
> if(c=='\r' || c=='\n')
> // ...
>
> The first check detects both '\r' and '\r' '\n' sequence and if none of them
> exist checks for '\n' alone.


But the problem with this is if end line is \r\n I will get after that
one emtpy line. (Because of \n.)


Mike
 
Reply With Quote
 
John Harrison
Guest
Posts: n/a
 
      05-07-2004

"Mike Mimic" <> wrote in message
news:c7ehnj$c0n$...
> Hi!
>
> I am programming small program which would use its own
> text based network protocol. I come to the problem with
> ending lines. I was thinking about ending them with \r\n
> combination. But the problem is that I would like that
> program would be tolerant to other endings (only \r or \n).
>
> So the question is if there is some efficient way to
> implement this? Is there some library which would do this?
> It should be platform independent.
>


I don't see this as anything other than a parsing issue. Presumably you are
parsing the content of lines in your program as well, so why not use
whatever techniques you are already using?

Unless the parsing task was really simple, this is an area where I would get
some help. One well established parsing tool is the flex/bison combination,
but there are loads more. Just google for parser generator.

John


 
Reply With Quote
 
Mike Mimic
Guest
Posts: n/a
 
      05-07-2004
Hi!

John Harrison wrote:
> I don't see this as anything other than a parsing issue. Presumably you are
> parsing the content of lines in your program as well, so why not use
> whatever techniques you are already using?


I would like to have line by line so that I can than know where is the
end of line and so on. I think that it will be easier for me to have
a line to parse than to have multiple lines.

> Unless the parsing task was really simple, this is an area where I would get
> some help. One well established parsing tool is the flex/bison combination,
> but there are loads more. Just google for parser generator.


Anyone any other suggestions?


Mike
 
Reply With Quote
 
John Harrison
Guest
Posts: n/a
 
      05-07-2004

"Mike Mimic" <> wrote in message
news:c7g3s0$l5b$...
> Hi!
>
> John Harrison wrote:
> > I don't see this as anything other than a parsing issue. Presumably you

are
> > parsing the content of lines in your program as well, so why not use
> > whatever techniques you are already using?

>
> I would like to have line by line so that I can than know where is the
> end of line and so on. I think that it will be easier for me to have
> a line to parse than to have multiple lines.
>
> > Unless the parsing task was really simple, this is an area where I would

get
> > some help. One well established parsing tool is the flex/bison

combination,
> > but there are loads more. Just google for parser generator.

>
> Anyone any other suggestions?
>


Well then you are going to have to write your own line reading function

string read_line(istream& in)
{
string line;
char ch;
while (in.get(ch))
{
if (ch == '\n')
break;
if (ch == '\r')
{
if (in.get(ch) && ch != '\n')
in.putback(ch);
break;
}
line += ch;
}
return line;
}

Untested code.

john


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Read a file line by line and write each line to a file based on the5th byte scad C++ 23 05-17-2009 06:11 PM
How do I tell the difference between the end of a text file, and an empty line in a text file? walterbyrd Python 7 05-17-2007 06:02 AM
How to read a text file line by line and remove some line kaushikshome C++ 4 09-10-2006 10:12 PM
Protocol Chart - Learn how to use a Protocol Analyzer news.comcast.giganews.com Wireless Networking 0 08-21-2004 04:35 PM
When i try to implement a server program giving UDP as protocol , it works fine , but if the same code is executed with TCP as protocol option, it gives an error. Tompyna Perl Misc 4 02-17-2004 06:51 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57