First off:
How could strlen possibly know the length of a string that doesn't already have a NULL?
Anyway, from man fgets:
So your data already had a NULL.
This is perfectly fine though. You're not transmitting the NULL terminator, since strlen() doesn't count that in the length, so you need to add it.
As for your select problem, I reviewed some of my old threads in which I discovered that you have to FD_SET the file descriptors you want select() to check before you call select() every loop. select() clears things that have no data, but never, ever sets the ones that do.
I'll see if I have time to compile and test your program later
---------- Post updated at 12:24 PM ---------- Previous update was at 11:48 AM ----------
You can put more than one thing in a printf, you know. And it's really helpful to put in newlines so multiple statements don't get glued together. And when you do, you should be adding newlines to the END, not the BEGINNING.
And when you learned that you that you should be using #define's instead of integers, I think you missed the point. MAX, MAX-1, STDIN_FILENO, and so forth are meaningful, but there's no point #defining ONE or TWO or ZERO. That doesn't tell you why you're using 0, making it unhelpful. And it stops you from changing it later -- MAX can be whatever you want, but FIVE sure can't!
---------- Post updated at 12:50 PM ---------- Previous update was at 12:24 PM ----------
You're not checking the return value of select, and should. I'll be posting a revised version soon.
---------- Post updated at 12:54 PM ---------- Previous update was at 12:50 PM ----------
Here ya go:
Last edited by Corona688; 07-01-2011 at 04:01 PM..
Hello,
I actually try to make client-server program.
I'm using SCO OpenServer Release 5.0.0 and when I try to compile my code (by TELNET) I've got this error :
I'm just using this simple code :
and I get the same error if I use :
If someone can help me,
Thanks (2 Replies)
hello socket programming expert,
I having difficulties in understanding how select() function in socket programming work.... I'm trying to create my own peer-to-peer chat or file transfer program by using the select() function.... Therefore does anyone had any tutorial or source code that... (4 Replies)
I have a socket and a message queue over which i am trying to multiplex input using select().
When data comes over socket the select works but when it comes over message queue the select is not detecting it .
Create_Q gets the identifier of the messege queue.
... (1 Reply)
Hi,
I was porting ipv4 application to ipv6; i was done with TCP transports. Now i am facing problem with SCTp transport at runtime.
To test SCTP transport I am using following server and client socket programs. Server program runs fine, but client program fails giving Invalid Arguments for... (0 Replies)
Hi all,
On the server side, one socket is used for listening, the others are used for communicating with the client.
My question is: if i want to set option for socket, which socket should be set on?
If either can be set, what's the different?
Again, what's the different if set option... (1 Reply)
Why does this socket function only read the first 1440 chars of the stream. Why not the whole stream ? I checked it with gdm and valgrind and everything seems correct...
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <string.h>
#include... (3 Replies)
Dear Experts,
i am compiling my code in suse 4.1 which is compiling fine,
but at runtime it is showing me for socket programming error no 88
as i searched in errno.h it is telling me socket operation on non socket,
what is the meaning of this , how to deal with this error , please... (1 Reply)
Hi, I am a newbie about network programming. All codes come from this book: UNIX Network Programming Volume 1, Third Edition.
It is a TCP server by use select()
int main(int argc, char **argv) {
int i, maxi, maxfd, listenfd, connfd, sockfd;
int ... (2 Replies)
Hello,
I have kubuntu on my laptop and now I decided to switch to Windows 7. I made the bios settings properly (first choice is boot from cd\vd) but I see the error
" reboot and select proper Boot device or insert Boot media in select Boot device and press a key "
I have tried CD and... (0 Replies)
I need clarification on whether it is okay to set socket options on a listening socket
simultaneously when it is being used in an accept() call?
Following is the scenario:-
-- Task 1 - is executing in a loop - polling a listen socket, lets call it 'fd', (whose file descriptor is global)... (2 Replies)