How to send EOF using socket connection

How to send EOF using socket connection

Post by Carfield Yi » Thu, 06 Apr 2000 04:00:00



How to send EOF using socket connection? I have try "\n", "\r\n" and
"\0" but all don't work.
 
 
 

How to send EOF using socket connection

Post by John Carrol » Thu, 06 Apr 2000 04:00:00


I can assume that you are sending text files. EOF is usually indicated
by -1 or ^D.
EOF is defined in stdio.h

you can append EOF to a string by doing the following

char eof;

eof = (char) EOF;
/* explicitly append the eof to the string */
string[sizeof(string) ] = eof;
/* explicitly null terminate the string */
string[sizeof(string) + 1] = '\0';

/* This code should work */
send( socket_descriptor, string, sizeof(string), 0);

John


> How to send EOF using socket connection? I have try "\n", "\r\n" and
> "\0" but all don't work.


 
 
 

How to send EOF using socket connection

Post by Erik Max Franci » Thu, 06 Apr 2000 04:00:00



> I can assume that you are sending text files. EOF is usually indicated
> by -1 or ^D.
> EOF is defined in stdio.h

According to ANSI, EOF is defined as a negative integral constant.
Usually it's defined as -1, obviously.  It's never defined as 4.

Quote:> char eof;

> eof = (char) EOF;

EOF expands to a negative int.  (char) EOF will almost certainly give
you a different constant, since sizeof(char) < sizeof(int) on most
systems.

Quote:> /* explicitly append the eof to the string */
> string[sizeof(string) ] = eof;

But you won't be appending an end-of-file, because EOF is not a char.
Not to mention the fact that EOF as an end-of-file marker is something
used by stdio, not by the physical media which are being used.

--

    Alcyone Systems | web http://www.alcyone.com/max/ | q3a Product
       San Jose, CA | languages en, eo | icbm 37 20 07 N 121 53 38 W
                USA | 968.994 Ms p.L. | 272 days left | &tSftDotIotE

 
 
 

How to send EOF using socket connection

Post by Carfield Yi » Thu, 06 Apr 2000 04:00:00


Then how can I tell the server that I have sent all data, if all data is a
unknown length string. Any special character should I append at the end of
that string?


> > I can assume that you are sending text files. EOF is usually indicated
> > by -1 or ^D.
> > EOF is defined in stdio.h

> According to ANSI, EOF is defined as a negative integral constant.
> Usually it's defined as -1, obviously.  It's never defined as 4.

> > char eof;

> > eof = (char) EOF;

> EOF expands to a negative int.  (char) EOF will almost certainly give
> you a different constant, since sizeof(char) < sizeof(int) on most
> systems.

> > /* explicitly append the eof to the string */
> > string[sizeof(string) ] = eof;

> But you won't be appending an end-of-file, because EOF is not a char.
> Not to mention the fact that EOF as an end-of-file marker is something
> used by stdio, not by the physical media which are being used.

> --

>     Alcyone Systems | web http://www.alcyone.com/max/ | q3a Product
>        San Jose, CA | languages en, eo | icbm 37 20 07 N 121 53 38 W
>                 USA | 968.994 Ms p.L. | 272 days left | &tSftDotIotE

 
 
 

How to send EOF using socket connection

Post by mike burrel » Thu, 06 Apr 2000 04:00:00



> Then how can I tell the server that I have sent all data, if all data is a
> unknown length string. Any special character should I append at the end of
> that string?

yes, you'll have to do this yourself in the protocol.

--
              /"\                              m i k e    b u r r e l l

               X        AGAINST HTML MAIL      http://mikpos.dyndns.org
              / \

 
 
 

How to send EOF using socket connection

Post by Tony R. Benne » Thu, 06 Apr 2000 04:00:00





>> Then how can I tell the server that I have sent all data, if all data is a
>> unknown length string. Any special character should I append at the end of
>> that string?

>yes, you'll have to do this yourself in the protocol.

Such as prefacing each 'send' with an integer containing the length of
the packet... and when you're done... send an extra packet containing a
length of -1...

The receiver, recv()'s the socket for the length of an integer to find out
how much it should read (if at all) on a second recv().

Just an idea...

-tony
--


 
 
 

How to send EOF using socket connection

Post by Barry Margoli » Thu, 06 Apr 2000 04:00:00




Quote:>Then how can I tell the server that I have sent all data, if all data is a
>unknown length string. Any special character should I append at the end of
>that string?

shutdown(socket_fd, 1);

is how you indicate that you're done sending data on that connection, but
still plan on reading from it.

If you're not going to read any more, either, just call close().

--

GTE Internetworking, Powered by BBN, Burlington, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.

 
 
 

How to send EOF using socket connection

Post by Marcu » Thu, 06 Apr 2000 04:00:00



> Then how can I tell the server that I have sent all data, if all data is a
> unknown length string. Any special character should I append at the end of
> that string?

Why not use non-blocking read(); and if you get EAGAIN there is no more
data (Well, there might be some left but you can use a select loop to
timeout and maybe do something like:

if (*ptr != '\0') then continue_parsing

--

                        /*
                           talos / AINT
                           www:   http://www.algonet.se/~talos

                        */

 
 
 

How to send EOF using socket connection

Post by Wolfgang Den » Thu, 06 Apr 2000 04:00:00



>Then how can I tell the server that I have sent all data, if all data is a
>unknown length string. Any special character should I append at the end of
>that string?

Use close() resp. shutdown() on the socket.

Wolfgang

--
Software Engineering:  Embedded and Realtime Systems,  Embedded Linux

I used to be indecisive, now I'm not sure.

 
 
 

1. how to send EOF after writing to socket



No.  EOF on a TCP socket corresponds to sending a FIN segment, which
indicates that no more data will be sent in that direction.

Those are the common solutions.  Another is to use an encoding method like
XDR or ASN.1/BER.

--

GTE Internetworking, Powered by BBN, Burlington, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.

2. Windows ping and Linux ping command?

3. Opening a socket connection while in a socket connection.

4. my DNS, domain name server won't work.

5. How to detect broken socket connection when sending message

6. Newbie: how do I change the shell prompt?

7. How to send ctrl-C over the socket connection

8. FTP server on RH 8.0 (psyche)

9. How to detect a socket connection broken when sending a message on Solaris

10. Client-Server , problem using send(socket,...) command .

11. Socket using send/recv

12. Client-Server,Problem using send(socket,..) command .