Anyone know how to use socket select() function?


 
Thread Tools Search this Thread
Top Forums Programming Anyone know how to use socket select() function?
# 1  
Old 01-17-2008
Data 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:

Code:
//server.c, which is the server side source code

........

select(highsocket+1, NULL, &writeset, NULL, (timeval*)0);

............

if (FD_ISSET(socket,&writeset)) 
{
    printf("Server is writing.......\n");
}

.............

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

Thank you

Last edited by draggy; 01-17-2008 at 10:48 AM..
# 2  
Old 01-17-2008
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:
# 3  
Old 01-17-2008
Quote:
Originally Posted by ramen_noodle
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
# 4  
Old 01-21-2008
Sample select server in FreeBSD ports

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:

ftp://ftp.freebsd.org/pub/FreeBSD/po...ntd-1.1.tar.gz

The entire source code is in liedent.d, about 300 lines of C source.
# 5  
Old 01-21-2008
Quote:
Originally Posted by softweyr
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:

ftp://ftp.freebsd.org/pub/FreeBSD/po...ntd-1.1.tar.gz

The entire source code is in liedent.d, about 300 lines of C source.
Thank you :-D
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Socket and select

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)
Discussion started by: naresh046
3 Replies

2. Programming

I am a little bit confused in a socket example through select()

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)
Discussion started by: sehang
2 Replies

3. Programming

socket function to read a webpage (socket.h)

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)
Discussion started by: cyler
3 Replies

4. UNIX for Advanced & Expert Users

connect problem for sctp socket (ipv6 socket) - Runtime fail Invalid Arguments

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)
Discussion started by: chandrutiptur
0 Replies

5. Programming

Please help! accept function problems in Socket programming

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)
Discussion started by: natxie
1 Replies

6. Programming

connect() function in C++ socket programming

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)
Discussion started by: smdhd3
3 Replies

7. Programming

Multiplexing socket and message queue using Select()

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)
Discussion started by: shaurya.rastogi
1 Replies

8. Programming

select function

Dear all, I am using select function for the socket programming. What is the purpose of except fd's fd set in the argument. (0 Replies)
Discussion started by: nagalenoj
0 Replies

9. Shell Programming and Scripting

send function in socket

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)
Discussion started by: trupti_rinku
0 Replies

10. Programming

How to convert the "select" function into a "poll" function

i have a program using the select function but i want to convert it to poll... how can i do this? thanks in advance... :) (1 Reply)
Discussion started by: rbolante
1 Replies
Login or Register to Ask a Question