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
EOF expands to a negative int. (char) EOF will almost certainly giveQuote:> char eof;
> eof = (char) EOF;
But you won't be appending an end-of-file, because EOF is not a char.Quote:> /* explicitly append the eof to the string */
> string[sizeof(string) ] = eof;
--
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
> > 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
--
/"\ m i k e b u r r e l l
X AGAINST HTML MAIL http://mikpos.dyndns.org
/ \
>yes, you'll have to do this yourself in the protocol.
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
--
shutdown(socket_fd, 1);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?
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.
> 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?
if (*ptr != '\0') then continue_parsing
--
/*
talos / AINT
www: http://www.algonet.se/~talos
*/
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 .
12. Client-Server,Problem using send(socket,..) command .