473,397 Members | 2,033 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

End line of text based network protocol

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
Jul 22 '05 #1
5 1899
"Mike Mimic" <pp****@yahoo.com> wrote in message
news:c7**********@planja.arnes.si...
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

Jul 22 '05 #2
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
Jul 22 '05 #3

"Mike Mimic" <pp****@yahoo.com> wrote in message
news:c7**********@planja.arnes.si...
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
Jul 22 '05 #4
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
Jul 22 '05 #5

"Mike Mimic" <pp****@yahoo.com> wrote in message
news:c7**********@planja.arnes.si...
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
Jul 22 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: C-man | last post by:
Basically I want to create a battleship game that can be played by having two clients connect to it. I was wonder what the best networking principal would be. Basically I suppose I would have to...
11
by: Ed Suominen | last post by:
I'm thinking of implementing a real-time collaborative text editor in Python using Twisted. An initial plan is to use a Twisted PB server daemon that accepts user:password:file connections from...
0
by: dtSearch | last post by:
Press Contact: Belinda Banks S&S Public Relations (212) 946-2823 Belinda@sspr.com Announcing New dtSearch® Product Line Version Release Adds Broader Spider Capabilities to dtSearch Desktop,...
0
by: dtsearch | last post by:
Announcing dtSearch® Product Line Release With New Terabyte Indexer New Version Can Index Over a Terabyte of Text in a Single Index, With Indexed Search Time Typically Under a Second BETHESDA,...
14
by: DaveC | last post by:
I know this is the wrong group but I need a little pointing in a direction please. I need to write an implementation of a yet to be published protocol. It is transported over the internet via...
6
by: John Walton | last post by:
Hello, everyone. I just began school, and they already assigned us science fair. Since I'm in 8th grade, I get to do demonstrations for our projects. I'm probably going to demonstrate Python's...
16
by: Philippe C. Martin | last post by:
Hi, I am trying to change the data in a form field from python. The following code does not crash but has no effect as if "form" is just a copy of the original html form. Must I recreate the...
14
by: David W. Fenton | last post by:
I'm no stranger to this error message, but I have a client who is experiencing it, but, fortunately, without any actual data corruption, and it's driving them made. Their inability to grasp that...
1
by: polaris431 | last post by:
I would like to obtain encypted data over a network in real-time. The nature of the data and process is as follows... A physical hardware device is located at some remote location. When the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.