Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Problem with Multi-User Server__Please need Help!

Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello There,

I'm trying to develope a Server that handles multi-users.
Users in my code,(That i am posting here), are allready many...
Please, I am trying to communicate every user with each other, but Unfortunatly i can't found the wrong in my code.

My server test is:

public class TheServer {//extends Thread {
protected int PORT=23;
/** Creates a new instance of AMUD */
public TherServer() {

public static void main(String[] args)throws Exception {
TheServer Server=new TheServer();
if ( args.length != 0 )Server.PORT = Integer.valueOf(args[0]).intValue ();
ServerSocket SERVER=new ServerSocket(Server.PORT);
System.out.println("SERVER started on port "+Server.PORT);

boolean header=true;

while (header)

Socket CLIENT=SERVER.accept();

testClass PROTOCOL=new testClass(CLIENT);

new Thread(PROTOCOL,"Server"+Thread.activeCount() + 1).start ();

}catch(Exception e){System.out.println(e);}


And the *protocol* class of the server is:

import java.util.*;
public class testClass implements Runnable {

Socket connection;

testClass(Socket connection) throws Exception {


public void run() {

System.out.println("Allocation Input Verifier:System");String command=new String();

boolean state=false;


PrintWriter ud = new PrintWriter(connection.getOutputStream());
BufferedReader ind =
new BufferedReader(new InputStreamReader(connection.getInputStream()));



System.out.println("User %"+user+"% :["+command+"] at port :"+connection.getPort());

System.out.println("User %"+user+"% :["+command+"] at port :"+connection.getPort()+" DISCONNECTED");


}catch(Exception eX){System.out.println("Run Exception + "+eX);}



When I compile Server class, and When i run it, Server is alive. Users Connecting with telnet using:
%> telnet 23
So instances of users connecting without problem.

My problem is:
I can't do users to communicate with each other.Something like Chat server.
What should I use?
Can you reply me a easy sample code to understand the way of true multi-users connections?

Thanks for the help, if any!
Nik Lammar.
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Idonno much about telnet, but for peer-to-peer chat the simplest approach might be plain sockets. Here's one way to look at it ...

Each client opens a ServerSocket on some port. You can start by trying a predefined port number, but any port is ok.

Each client registers with the server by sending it's IP address & port number. This tells the server that the client is available. Clients might register with a variety of lookup keys, eg chatroom names or topic names that they want to participate in.

One client sends a message to the server. The server looks through its registry, finds all other clients interested in the topic, gets the server socket address for each one and forwards the message.

This is kind of a "painting on cave walls" level approach. You can get a lot fancier fer sure, but maybe it will get some ideas started.
Nik lammar
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Stan,
I solve the problem, thanks for your time.
I think, P2P connections are more difficult, and especially when there is a server that tracks all user-clients for statistics and other perposes.

Anyway thanks again for your help.
These you've post surelly will help me in my developement proccess later this project!

Nik Lammar
All of life is a contant education - Eleanor Roosevelt. Tiny ad:
Thread Boost feature
    Bookmark Topic Watch Topic
  • New Topic