Chat server / client


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Chat server / client

  1. #1
    Join Date
    Oct 2004
    Posts
    311

    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

  2. #2
    Join Date
    Mar 2004
    Posts
    635
    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

  3. #3
    Join Date
    Oct 2004
    Posts
    311
    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

  1. client server help
    By rohan076 in forum Java
    Replies: 4
    Last Post: 03-28-2006, 03:32 PM
  2. two server and many client....
    By collinm in forum Java
    Replies: 1
    Last Post: 10-06-2005, 03:35 PM
  3. Client server communication with Winsock
    By Calderara Serge in forum Enterprise
    Replies: 1
    Last Post: 07-24-2002, 12:40 AM
  4. Microsoft Sql Server 2000 Client DLL
    By Ramdas in forum Database
    Replies: 0
    Last Post: 05-16-2001, 02:57 PM
  5. 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
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center