multiple threads, java chat client

DeanR

I'm developing a simple chat client and I would need the server to handle multiple threads (1 per connection)

At the moment I only have 1 user and 1 connection

Thread con = new Thread(new Connection());
con.start();

Connection() is responsible for listening for messages from this particular connection and broadcasting them to each client (at the moment there is only one)

I plan to create an array of Connection objects and create a thread for each but i'm not sure what i should do from here on, what does 'con' actually represent in this case?

Paul Gray

If Connection is a custom class containing information about a certain connection (which I assume it is), then you don't want to pass it into the Thread.

You could probably benefit from reading the Java documentation concerning Defining and Starting a Thread. What you probably want is to start a new Thread() every time you receive a connection from a client. You can accomplish this with this snippet:

new Thread(){
    public void run() {
        System.out.println("blah");
    }
}.start();

Whatever code you put inside the run() function will get run inside a thread.

To answer the second part of you question, in your example, your con object represents a single instance of a thread of execution.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Multiple client "chat"

From Dev

chat in java not synchronized (sockets, threads)

From Dev

Server client chat room in Java

From Dev

Client Server chat application in java

From Dev

Multi client chat application In java

From Dev

Client Server chat application in java

From Dev

Multiple Threads For a Java Timer

From Dev

RabbitMQ channels and threads in Java client

From Dev

Making a chat app with a java client and php server

From Dev

Java - server networking specific client chat

From Dev

Exampels on a Server-Client-Chat applikation on JAVA

From Dev

Multithreaded client server chat application in java

From Dev

Making a chat app with a java client and php server

From Dev

Client Server Chat Application in Java without broadcasting

From Dev

Accepting multiple simultaneous client sockets on their own threads

From Dev

How to make a Thrift client for multiple threads?

From Dev

Jboss 7 multiple threads on client side

From Dev

Accepting multiple simultaneous client sockets on their own threads

From Dev

Multiple Client Threads can connect, threads are accepted in sequential order

From Dev

Synchronizing queue in Java on multiple threads

From Dev

Running multiple threads concurrently in java

From Dev

Variable synchronization in multiple Java Threads

From Dev

Java start multiple threads in a class

From Dev

Java Multiple Threads equals multiple Cores?

From Dev

Java Chat Program: Client Class not working due to null pointer exception

From Dev

Java Client/Server chat room sending messages as objects

From Dev

Java Server-Client with Multiple Client

From Dev

Java: Sending messages to a JMS queue with multiple threads

From Dev

Creating multiple threads for writing files to Disk, Java

Related Related

  1. 1

    Multiple client "chat"

  2. 2

    chat in java not synchronized (sockets, threads)

  3. 3

    Server client chat room in Java

  4. 4

    Client Server chat application in java

  5. 5

    Multi client chat application In java

  6. 6

    Client Server chat application in java

  7. 7

    Multiple Threads For a Java Timer

  8. 8

    RabbitMQ channels and threads in Java client

  9. 9

    Making a chat app with a java client and php server

  10. 10

    Java - server networking specific client chat

  11. 11

    Exampels on a Server-Client-Chat applikation on JAVA

  12. 12

    Multithreaded client server chat application in java

  13. 13

    Making a chat app with a java client and php server

  14. 14

    Client Server Chat Application in Java without broadcasting

  15. 15

    Accepting multiple simultaneous client sockets on their own threads

  16. 16

    How to make a Thrift client for multiple threads?

  17. 17

    Jboss 7 multiple threads on client side

  18. 18

    Accepting multiple simultaneous client sockets on their own threads

  19. 19

    Multiple Client Threads can connect, threads are accepted in sequential order

  20. 20

    Synchronizing queue in Java on multiple threads

  21. 21

    Running multiple threads concurrently in java

  22. 22

    Variable synchronization in multiple Java Threads

  23. 23

    Java start multiple threads in a class

  24. 24

    Java Multiple Threads equals multiple Cores?

  25. 25

    Java Chat Program: Client Class not working due to null pointer exception

  26. 26

    Java Client/Server chat room sending messages as objects

  27. 27

    Java Server-Client with Multiple Client

  28. 28

    Java: Sending messages to a JMS queue with multiple threads

  29. 29

    Creating multiple threads for writing files to Disk, Java

HotTag

Archive