-
Chat server / client
Hello all,
I'm currently working on a chat server / client and I'm implementing it using sockets. However, since there are several ways to implement sockets in Java I thought I'd get some ideas from you guys. I'm currently leaning towards non-blocking server sockets instead of the blocking server sockets. This is because a blocking serevr socket takes up system resources while not doing anything, which is not good. However, I'm still not sure how to proceed on the client side.
Should I keep the socket open indefinately, or close it after each send? The first approach sounds like the way to go, since you can then send messages back from the srever to the client when needed. But wouldn't that approach top of the number of sockets you can open towards the server eventually?
If so, it might be better to go for the second approach and just poll for new messages every second or so. However, this has the added overhead of creating a new socket every second, which is also a drain on system resources.
Your thoughts on this would be appreciated.
Mark
-
Keep the socket open with the server.
[qoute]But wouldn't that approach top of the number of sockets you can open towards the server eventually[/quote]
The client should only have 1 connection to the server.
This might help answer some other questions:
http://java.sun.com/developer/online...a2/socket.html
-
I know, it's not the client I'm worried about...
My problem is, the moment I get for example 100 cleints that want to connect to my chat server, I'll have 100 open sockets on the server, as well as 100 client threads.
Bte. I found an example which fixes it for me... I can now do non-blocking sockets on server AND client side. This mean I only need one thread on the server to handle all the connections from all the clients simultanious.
I will probably be setting up a new thread for each room though, but this is a much lower thread count then one thread per suer.
Mark
Similar Threads
-
By rohan076 in forum Java
Replies: 4
Last Post: 03-28-2006, 03:32 PM
-
Replies: 1
Last Post: 10-06-2005, 03:35 PM
-
By Calderara Serge in forum Enterprise
Replies: 1
Last Post: 07-24-2002, 12:40 AM
-
By Ramdas in forum Database
Replies: 0
Last Post: 05-16-2001, 02:57 PM
-
By Sreedhar Kaluva in forum Database
Replies: 0
Last Post: 02-13-2001, 08:15 PM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks