question on puts, gets and eof? 
Author Message
 question on puts, gets and eof?

I'am trying to test the socket command under windows 95.

On the client side I do:
socket.....
puts socket "string"
flush socket

On the server side:
filevent ....accept $socket

proc accept
{
if { [eof $socket]}
{close $socket}
set string [gets $socket]
puts string

Quote:
}

The problem is that the eof condition is never satisfied although
I did not use the -nonewline at the client side with puts.
How can I send a text and close the socket from the server side when
the file reaches the end?

I would appreciate some help.

Francois



Mon, 01 Feb 1999 03:00:00 GMT  
 question on puts, gets and eof?

Quote:

> proc accept
> {
> if { [eof $socket]}
> {close $socket}
> set string [gets $socket]
> puts string
> }

> The problem is that the eof condition is never satisfied although
> I did not use the -nonewline at the client side with puts.
> How can I send a text and close the socket from the server side when
> the file reaches the end?

Francois,

I am assuming you have defined socket as a global variable, or are
passing the parameter into your function.  You would have to be, or your
script would generate an error.  So, I'm going to assume you aren't
making any silly mistakes.

In that case, I think the problem is that when you are reading the data
on the client side and sending it, line by line, you are using the same
procedure only backwards...if you are sending an explicit eof character
through the "puts" loop, as it seems you may very well be doing, the
problem would lie there.  For one, puts will not recognize eof, as it (I
believe, anyone want to check up on this?) reads up everything UNTIL the
eof, then konks out.  

So, the problem is most likely with the puts command itself.  You might
want to verify that puts does indeed accept an eof character as valid
data.  If not, try doing the same thing within a loop, character by
character, using the "read" command.

Hope this helps.

Bryce



Mon, 01 Feb 1999 03:00:00 GMT  
 question on puts, gets and eof?


:So, the problem is most likely with the puts command itself.  You might
:want to verify that puts does indeed accept an eof character as valid
:data.  If not, try doing the same thing within a loop, character by

On Unix at least, there is no 'EOF' character.  Perhaps the platform
determines how things work in this case?

--

:s <URL:http://www.teraform.com/%7Elvirden/> <*> O- "We are all Kosh."
:s Unless explicitly stated to the contrary, nothing in this posting should
:s be construed as representing my employer's opinions.



Tue, 02 Feb 1999 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. eof on channel, not eof on transform: [eof] returns true

2. gets from socket got eof (multithread)

3. gets and eof?

4. while { !eof } gets extra line

5. gets stdin EOF as of Tcl 8.0p2

6. gets & eof

7. EditableMovie.EOF goes 1 frame past EOF?

8. eof-error-p/eof-value

9. Getting awk (or sed or anything else) to put single quotes into file

10. Putting or Getting multiple files with RxFtp

11. puts and gets over IP

12. BUG?: HP-UX 10.20 and IO#gets followed by IO#puts

 

 
Powered by phpBB® Forum Software