![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| read and write from a file | rinku | Shell Programming and Scripting | 2 | 01-10-2008 10:22 PM |
| read/write socket error | gio | High Level Programming | 2 | 04-16-2007 08:52 PM |
| sed to read and write to very same file | 435 Gavea | Shell Programming and Scripting | 5 | 06-29-2006 08:04 PM |
| popening for read and write | szzz | High Level Programming | 1 | 11-18-2003 09:05 AM |
| read, write & STDOUT_FILENO.... | M3xican | High Level Programming | 2 | 07-17-2002 01:41 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
#1
|
|||
|
|||
|
Problem with read & write
Hello mates:
I met problem with using read() & write(). I m trying to use read twice on client first time is the size of buffer, 2nd time is the buffer. I think I have to, coz I dnot know file size. So, I write twice on server as well -- 1st, filesize; 2nd, buffer. The problem is, sometimes, I cannot get anything at 2nd time. The file I got is empty, nothing. However, if I put a sleep(1) before the 2nd write() on server, I can read( but this sometimes may cause a segmentation fault)... i.e.: Client Server read() 1st write() 1st <-----both OK (if I put a sleep(1)here, it's OK) read() 2d write() 2nd <-----problem Does anybody know the reason? BEST REGARDS, Elton |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
If you are using sockets send() and recv() offer much greater control over your data transmission
|
|
#3
|
|||
|
|||
|
Quote:
Check to make sure you're recieving the number of bytes you intended. I think you might be getting crazy numbers for filesize, which could cause the crash. |
|
#4
|
||||
|
||||
|
Try them and if the error disappears then the reason exists
|
|
#5
|
|||
|
|||
|
How so? Even if the error goes away, the program still lacks the error-checking to handle them. It should fail, not crash.
|
|
#6
|
|||
|
|||
|
It's really a frustrating problem
I m trying to use 2 write() in a row, first write() is used to send file size, 2nd send the file. On client side, I use malloc() for the buf size and free later. Current situation is if I put sth (like sleep(1) or a read()) btw 2 write() , they both work fine. Othrewise, I lose some bytes on client side which is from the 2nd write(). That makes the browser cannnot recognize the HTTP header.... REGARDS, ELton |
|
#7
|
||||
|
||||
|
OK, I suggest that you set up a proper handshake. Currently your scenario is like this:
server -- write size client -- read size server -- write data_buffer client -- read data_buffer Change that to: server -- write size client -- read size client -- write ACK server -- read ACK server -- write data_buffer client -- read data_buffer client -- write ACK and so on.... So it will never be that your server is continuously writing to a socket that the client is not able to read cause it crashed... |
||||
| Google The UNIX and Linux Forums |