C Programming: Anyone know how to use socket select() function?
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 related to either one of the program, which I'm trying to create?
My problem is how to get the "write" in select() function working?
Let say:
and now, how do I get the server side to print the word "Server is writing......." ? I hope you guy understand what I mean.......
btw, I'm using NetBDS and using C programming....... hoping someone can help me out :-D
I've attached a hasty, single process server (without any signal handling) example that works on my FreeBSD 6.0 host. Hopefully it will be of assistance. I'd suggest running indent against it. There are also very good arguments for not using select in favor of pselect. Also for high capacity servers maybe kqueue would be better.
HTH
This User Gave Thanks to ramen_noodle For This Post:
I've attached a hasty, single process server (without any signal handling) example that works on my FreeBSD 6.0 host. Hopefully it will be of assistance. I'd suggest running indent against it. There are also very good arguments for not using select in favor of pselect. Also for high capacity servers maybe kqueue would be better.
HTH
Thank you for reply and your example is very good :-D
btw, I will come back later in time to report my progress on how is the development is going on :-D
My 'liedentd' is a simple select(2)-based server program that is a good example of how to write a high-performance select loop. It is available in the FreeBSD ports system, under security/liedentd, or you can fetch the source from:
My 'liedentd' is a simple select(2)-based server program that is a good example of how to write a high-performance select loop. It is available in the FreeBSD ports system, under security/liedentd, or you can fetch the source from:
I have created two sockets and binded both. My requirement is that 2nd socket must send/ recv data only on expiration of timeval(tv). but the 1st socket must keep on send/recv the data without waiting for the 2nd socket completion......
I have posted my code below......
In this code the 2nd... (3 Replies)
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)
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)
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,
I have a client-server socket program. It has been working fine for over a year, but recently it started to show strange behavior.:confused:
After the server program runs for a while, it will show in the top command saying it is using lots of CPU, MEM. I assume it means the server code is... (1 Reply)
Hello All,
I have a problem using connect(...) function in C++. I am using SSH from my windows system to connect it to linux server. The program works fine if I run it directly in Linux machine but I need it to run through windows machine.
The function returns -1 and so my program terminates.
... (3 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 All,
I encountered a stange problem while doing a perl script to use socket. i need to transfer a file from client to sever. but error came as argument missing in send function.........Plz tell me the wt r the arguments in send and recv functions....... (0 Replies)