![]() |
|
#1
|
|||
|
|||
infinite loop!!!hi ppl .. i did a program for bitstuffing..the client will get the frames ,append it with start and end frames("01111110") and send it to the server along with stuffing it(adding a zero after five 1's)...the server has to unstuff it by removing the extra starting and end frames and the extra zeros added..if i give small inputs it works but for large inputs it ends up in an infinite loop..pl help
server CPP / C++ / C Code:
client CPP / C++ / C Code:
|
|||
|
#2
|
|||
|
|||
Re: infinite loop!!!Quote:
Could you give me an example of a short frame for which bit-stuffing is necessary? Do your programs work with such a message? I'll give you one: a message consisting of the three ASCII characters "a?b" (Hex values are 0x61, 0x3f, 0x62.) How many bits must be transmitted in the message frame (including starting and ending frame sync bytes)? How many bytes? What are the bytes? Does your client program transmit the correct number of correct bytes for this message? Does the server handle the frame correctly? Instead of getting muddled in the client-server aspects of the communication, have you tried simply writing the bytes of the frame to a file with the "client" program and reading the file with the "server" program. Note that with bit-stuffing, you might end up with some non-ASCII characters, so simply printing the bit-stuffed message bytes might or might not be enlightening. That's why short messages are important for testing. You can actually print out the bits of each message byte before and after stuffing to see what the program did with them. This may help you separate the bit-stuffing functionality from the sockets stuff, and should make it easier to test. Regards, Dave Footnote: As a practical matter, I question the efficacy of doing bit-stuffing at the message level (it's usually done at the PHY level so that the higher communications layers don't have to be changed if/when the characteristics of the physical channel change. For example Ethernet has its own way of assuring signal integrity regardless of the nature of the message. Similarly for WiFi, HDLC, etc. The program generating the message and handing it off to the communications channel never has to worry about bit-stuffing or other signal integrity measures. As an exercise in programming, I like the idea of using bit-stuffing to make you think in terms outside the usual messages made up of "bytes in" and "bytes out". I do think that testing/debugging would be easier with file I/O rather than client-server communications. I think it is very important to visualize what would make simple test cases (short messages with and without bit stuffing). Test with known messages for which you can manually (or mentally, or programmatically) create the exact bit streams to test against your program's behavior. Then (and only then) go for longer and longer messages. But that's just me. |
|
#3
|
||||
|
||||
Re: infinite loop!!!Hi!
edit>> Ok Dave was quick posting reply... and I also agree e.g. with the points about the data being binary... and therefore CPP / C++ / C Code:
edit2>> To handle it correctly the "read" function returns the amount of bytes actually read. So that value should be used instead of strlen. Furthermore function "recv" can be someways better than "read" because allows more control via usage of flags. ... quite a hotchpotch this.. but thanks for Dave for reminding me also about some important basics... |
Recent GIDBlog
Problems with the Navy (Chiefs) by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| breaking an infinite loop through stdin | pisuke | C Programming Language | 9 | 03-Jul-2007 21:19 |
| Text-Based Roulette Game | mfm1983 | C++ Forum | 5 | 29-Nov-2006 13:20 |
| C++ Aparently on infinite loop, but where? | Link | C++ Forum | 7 | 08-Sep-2006 09:40 |
| Array 1 dimensional help please asap | lion123 | C Programming Language | 10 | 18-Feb-2005 22:53 |
| messy loop help please | sammacs | C Programming Language | 6 | 26-Nov-2004 16:18 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The