can someone please explain to me how read write work in sock programming.
my assignment is to run a server and client. the client ask the server "who are you?" and the server replies with the servers name and date and time.
i cannot post my whole code here as its an ongoing assignment and i dont want anyone from my class to have access to my code before i submit.
server
/* transfer data */
//to print string "who are you?"
int nread = read ( client_sockfd, buf, SIZE );
write ( 1, buf, nread );
time ( &t );
gethostname(hostname, sizeof hostname);
sprintf ( buf, "%s", asctime ( localtime ( &t ) ) );
socklen_t len = strlen ( buf ) + 1;
write ( client_sockfd, buf, len );
write ( client_sockfd, hostname, strlen ( hostname ) + 1 );
close ( client_sockfd );
my question is do i have to call write() twice? how do i put both date-time and hostname on buf
client
string s = "Who are you?";
/* transfer data */
write ( sockfd, s, s.size() ); //--compile error
nread = read ( sockfd, buf, SIZE );
write ( 1, buf, nread );
close ( sockfd );
exit (0);
there is a compiling error in the client.
invalid conversion from ‘char’ to ‘const void*’
BasicClient.c:39: error: initializing argument 2 of ‘ssize_t write(int, const void*, size_t)’
can someone please help me?
drjay