IRC Server, Handling Clients!

Started by
6 comments, last by AABBFFLLUUGG 20 years ago
Hi, im in the process of having a stab at writing a super-simple irc-type server, and am using TCP. what should i do if more than 64 clients connect, as i know that the winsock implementation doesnt really like that many socket connections. how do big, established servers handle so many clients? thank-you
Advertisement
Winsock doesn''t like that? Or are you refering only to the limitations of select() on windows?

Generally, irc servers handle it by running on a better Operating System, but I''ll be accused of being biased, now.

Just for reference if any people searching for how to do this on linux find this post. Here''s a good resource.

For windows, I believe there''s some IO Completion Port thing? IOCP a quick google finds this
You can get around the 64 socket limitation by running multiple threads, using overlapped I/O, etc. For more detail about the actual limitations of Winsock, you might find this FAQ helpful.
wow! thanks a lot for the replies, that helps me out a lot. Time to do some reading!
AHA! now a problem that perhaps isnt exactly multiplayer based, but is related to threaded servers. i am using 2 threads at the moment in my server, 1 for doing all the socket input/output, and another to ping all clients to ensure they are active every n seconds. the connected user details are available as a std vector of a struct containing name, socket handle etc. which is stored in the communication thread. how can i allow the ping thread to access the vector of user info, inter-thread as it were.

thanks a lot everyone

(ps, as you can gather i am a total clueless noob when it comes to servers and winsock etc, if anyone knows of a good site about threading using winsock, i would appreciate it if they could let it be known to me, cheer )
quote:
the connected user details are available as a std vector of a struct containing name, socket handle etc. which is stored in the communication thread. how can i allow the ping thread to access the vector of user info, inter-thread as it were.


thats rather "simple" multithreading. you need access to the list itself (using *cough* global pointer var *cough* or pass it as thread creation data), and to make sure its threadsafe, you should have a serious look at "mutex", "semaphora" or in general thread safety. i think looking up and understanding mutexes will be enough. the linux posix threads implemention is pretty good for learning purposes, check out the manpages for pthread_mutex_init and pthread_mutex_destroy (you''ll also need pthread_mutex_lock/unlock).
almost any threading tutorial will cover mutexes in at least the second chapter, so you can look that up as well.

quote:
(ps, as you can gather i am a total clueless noob when it comes to servers and winsock etc, if anyone knows of a good site about threading using winsock, i would appreciate it if they could let it be known to me, cheer )


i do not think its a good idea to threads and sockets at the same time... rather focus on learning sockets first, set up a server and see how well it handles clients with a single thread. for waaaghtv i have developed a small single threaded server that managed up to 1000 simultaneous clients using sockets and select (yeah its very ugly <-> quickhack) on a duron 800 so i guess you will manage your few hundred irc connections as well.

threading can introduce very nasty bugs if you don''t know what you are doing so you''d better learn it in a seperate thread ;-)

--
Volker Schoenefeld
Student @ RWTH Aachen (Germany)
--Volker SchoenefeldStudent @ RWTH Aachen (Germany)
Look at the comment in the Windows header that defines fd_set. You can define your own maximum fd_set size as a compiler define in project options (or on the command line) and it''ll work. It''s just that the default is rather small.

As for whether you''ll get good performance out of select() on Windows... well, try it ;-) WinSock also have non-UNIX-like APIs for sockets, such as overlapped/asynchronous notification. You could go that route, if you want the server code to run on Windows only.
enum Bool { True, False, FileNotFound };
i''ve seen some comparisons (i think they made it for the phhttpd project to test the new /dev/epoll device on linux) which showed that winsock has serious problems reading beyond a certain amount of sockets. rather use several thread and only use the OS default value. on linux you should use epoll (when using patch 2.4 or new 2.6 kernel).
it really depends on a realstic estimate how many client connections you will receive. due to the nature of irc servers, you can also limit the amount of users to one server, and implement the server-server communication (see RFC 1459: http://www.cse.ohio-state.edu/cgi-bin/rfc/rfc1459.htm). then you can use a small server relay.

--
Volker Schoenefeld
Student @ RWTH Aachen (Germany)
--Volker SchoenefeldStudent @ RWTH Aachen (Germany)

This topic is closed to new replies.

Advertisement