Help with chat plz

Hi im really new to java so this question must be kinda easy so plz help
Im able to connect several clients with threads to a central server but how am i able to send the msgs to all the clients connected?
Some simple code would be really apreciated.
thx a lot.

A Solution can be like this.
make a static object of class vector in your main server class.
static vector connections=null;
If you are unaware of Vector class,refer any JAVA book.
you may initialise it in your constructor.
Now whenever your client connects, the thread which will be responsible for handling the connections, adds to the vector object connections. As the object connections is static, you would be able to directly call it and add the hostname of the client which just got connected. It should be something like this....
mainclass.connections.AddItem( " Hostname" );
I forgot the vector class methods for adding up items....try refering the same in a book.
This way you will be able to maintain a list of clients connected on your server.
Hope this resolves ur problem ..
Regards
Arvind

Similar Messages

  • PS TV help with chat !

    hello all ! back again for some help.i've recently got a 1TB ps4 bundle with PS TV.Great idea streaming the PS4 to another tv in the house for gaming.BUT i cant get a headset to work  ? chat in game is as important as playing the game right ? i have ps4 set up in a different room to the PSTV, PSTV connects to ps4 and plays no problem. i am using the ps4 controller with the PSTV and have tried the wired headset suppied with the ps4.also a  ps4 headset (Wired) purchased. trying to connect to party chat and the headsets are not working ?been to settings on the PSTV to see what i could find, the devise list shows the controller connected but no headset ?i also see connect bluetooth devices so have tried to connect the PS bluetooth headset from my PS3 but still no joy. help please with my PSTV chat Many Thanks 

    I have this very same problem.  Not got a solution but here's hoping someone somewhere knows. I tried all sorts the other other day. 

  • Help with Basics PLZ!

    So i'm really bad with Photoshop. I was trying to edit my pic seeing tutorial and understand the step given in this image --
    Plz If any one explain everything I need to do in it!
    How do i paste my image into the canvas? And how do i resize it?

    Hi Vicas.
    Ctrl+C will copy the source image.
    Ctrl+V will paste it into Ps.
    With the Move Tool (V), tic "Show Transform Controls". You will be able to resize the image by dragging a corner. Holding down Shift will maintain the aspect ratio.
    For best results, in your general preferences, choose an Image Interpolation mode approprate to your needs. Enlarging or reducing.
    Lee

  • Help with EJB plz

    Hi,
    I'm new to EBJs and am playing with an entity bean pretty much identical to the one on the J2EE tutorial but the home interface does not compile and I've got no idea why. Would really appreciate your help.
    COMPILER COMPLAINT*****
    C:\j2sdkee1.3\nim\src\ejb\addresses>javac AddressesHome.java
    AddressesHome.java:7: cannot resolve symbol
    symbol : class Addresses
    location: interface AddressesHome
    public Addresses Create(String id, String firstname, String lastname, St
    ring address, int contactno) throws RemoteException, CreateException;
    ^
    AddressesHome.java:10: cannot resolve symbol
    symbol : class Addresses
    location: interface AddressesHome
    public Addresses FindByPrimaryKey(String id) throws FinderException, Rem
    oteException;
    ^
    2 errors
    HOME INTERFACE*****
    import java.util.Collection;
    import java.rmi.RemoteException;
    import javax.ejb.*;
    public interface AddressesHome extends EJBHome
         public Addresses Create(String id, String firstname, String lastname, String address, int contactno) throws RemoteException, CreateException;
         public Addresses FindByPrimaryKey(String id) throws FinderException, RemoteException;
         public Collection FindByLastName(String lastname) throws FinderException, RemoteException;
    ADDRESSESSBEAN CLASS*****
    import java.sql.*;
    import javax.sql.*;
    import java.util.*;
    import javax.ejb.*;
    import javax.naming.*;
    public class AddressesBean implements EntityBean
         private String id;
         private String firstname;
         private String lastname;
         private String address;
         private int contactno;
         private Connection conn;
         private EntityContext context;
         private String dbName = "java:comp/env/jdbc/AddressesdB";
         public String ejbCreate(String id, String firstname, String lastname, String address, int contactno) throws CreateException
                   if(address == null || address.length() == 0)
                        throw new CreateException("You must specify an address");
                   try
                        insertRow(id, firstname, lastname, address, contactno);
                   catch(Exception e)
                        throw new EJBException("ejbCreate: " + e.getMessage());
                   this.id = id;
                   this.firstname = firstname;
                   this.lastname = lastname;
                   this.address = address;
                   this.contactno = contactno;
                   return id;
         public void changeAddress(String address)
              this.address = address;
         public String getAddress()
              return address;
         public void changeContactno(int contactno)
              this.contactno = contactno;
         public int getContactno()
              return contactno;
         public String getFirstname()
              return firstname;
         public String getLastname()
              return lastname;
         public String ejbFindByPrimaryKey(String primaryKey) throws FinderException
              boolean result;
              try
                   result = selectByPrimaryKey(primaryKey);
              catch(Exception e)
                   throw new EJBException("ejbFindByPrimaryKey: " + e.getMessage());
              if(result)
                   return primaryKey;
              else
                   throw new ObjectNotFoundException("Row for id " + primaryKey + " not found");
         public Collection ejbFindByLastName(String lastname) throws FinderException
              Collection result;
              try
                   result = selectByLastName(lastname);
              catch(Exception e)
                   throw new FinderException("ejbFindByLastName :" + e.getMessage());
              return result;
         public void ejbRemove()
              try
                   deleteRow(id);
              catch(Exception e)
                   throw new EJBException("ejbRemove : " + e.getMessage());
         public void setEntityContext(EntityContext context)
              this.context = context;
              try
                   makeConnection();
              catch(Exception e)
                   throw new EJBException("Unable to connect to database: " + e.getMessage());
         public void unsetEntityContext()
              try
                   conn.close();
              catch(Exception e)
                   throw new EJBException("unsetEntityContext: " + e.getMessage());
         public void ejbActivate()
              id = (String)context.getPrimaryKey();
         public void ejbPassivate()
              id = null;
         public void ejbLoad()
              try
                   loadRow();
              catch(Exception e)
                   throw new EJBException("ejbLoad: " + e.getMessage());
         public void ejbStore()
              try
                   storeRow();
              catch(Exception e)
                   throw new EJBException("ejbStore: " + e.getMessage());
         public void ejbPostCreate(String id, String firstname, String lastname, String address, boolean contactno)
         /****************************** DataBase Routines ******************************/
         private void makeConnection() throws NamingException, SQLException
              InitialContext ic = new InitialContext();
              DataSource ds = (DataSource) ic.lookup(dbName);
              conn = ds.getConnection();
         private void insertRow(String id, String firstname, String lastname, String address, int contactno) throws SQLException
              String insertStatement = "inset into ADDRESSES values (?, ?, ?, ?, ?)";
              PreparedStatement prepStmt = conn.prepareStatement(insertStatement);
              prepStmt.setString(1, id);
              prepStmt.setString(2, firstname);
              prepStmt.setString(3, lastname);
              prepStmt.setString(4, address);
              prepStmt.setDouble(5, contactno);
              prepStmt.executeUpdate();
              prepStmt.close();
         private void deleteRow(String id) throws SQLException
              String deleteStatement = "delete from ADDRESSES where id = ?";
              PreparedStatement prepStmt = conn.prepareStatement(deleteStatement);
              prepStmt.setString(1, id);
              prepStmt.executeUpdate();
              prepStmt.close();
         private boolean selectByPrimaryKey(String primaryKey) throws SQLException
              String selectStatement = "select id from ADDRESSES where id = ? ";
              PreparedStatement prepStmt = conn.prepareStatement(selectStatement);
              prepStmt.setString(1, primaryKey);
              ResultSet rs = prepStmt.executeQuery();
              boolean result = rs.next();
              prepStmt.close();
              return result;
         private Collection selectByLastName(String lastname) throws SQLException
              String selectStatement = "select id from ADDRESSES where lastname = ? ";
              PreparedStatement prepStmt = conn.prepareStatement(selectStatement);
              prepStmt.setString(1, lastname);
              ResultSet rs = prepStmt.executeQuery();
              ArrayList a = new ArrayList();
              while(rs.next())
                   String id = rs.getString(1);
                   a.add(id);
              prepStmt.close();
              return a;
         private void loadRow() throws SQLException
              String selectStatement = "select firstname, lastname, address, contactno from ADDRESSES where id = ?";
              PreparedStatement prepStmt = conn.prepareStatement(selectStatement);
              prepStmt.setString(1, this.id);
              ResultSet rs = prepStmt.executeQuery();
              if(rs.next())
                   this.firstname = rs.getString(1);
                   this.lastname = rs.getString(2);
                   this.address = rs.getString(3);
                   this.contactno = rs.getInt(4);
                   prepStmt.close();
              else
                   prepStmt.close();
                   throw new NoSuchEntityException("Row for id " + id + " not found in the dataBase");
         private void storeRow() throws SQLException
              String updateStatement = "update ADDRESSES set firstname = ?, lastname = ?, address = ? contactno = ? where id = ?";
              PreparedStatement prepStmt = conn.prepareStatement(updateStatement);
              prepStmt.setString(1, firstname);
              prepStmt.setString(2, lastname);
              prepStmt.setString(3, address);
              prepStmt.setInt(4, contactno);
              prepStmt.setString(5, id);
              int rowCount = prepStmt.executeUpdate();
              prepStmt.close();
              if(rowCount == 0)
                   throw new EJBException("Storing row for id " + id + " failed.");
    }

    EJB questions should be posted in the EJB forum! :=)
    I did find the compiler message a bit strange. Usually if I don't have a class defined it complains that it cannot find package_name.class_name (when I'm using packages for my own code).

  • Help with McAfee plz

    Hi to all Im new to this site/forum and would like some help plz
    Just installed Mcafee from BT and I was wondering if anyone else is using it ?
    my question is Im trying to find in the settings where you can exclude files/folders/ drives(external) from being scanned  but I cant find it any where in any of the settings
    ca anyone help plz
    n
    thanks in advance

    Click on the shield bottom right of screen:
    Select Virus and spyware protection
    Select Scan your PC
    Select Run a custom scan
    Then there are a number of options for you to chooses what to scan.
    However I would get a different anti virus software as the one thing I do not like about this is that it has a mind of its own when it comes to updates and will update when it wants to which slows the PC down and whatever you do you can not stop the update. This is very annoying if you are trying to do something which is time dependent.

  • Help with program plz (long code)

    anyone know how i can fix these 2 errors:
    Driver2.java:47: code is already defined in main(java.lang.String[])
    String code = JOptionPane.showInputDialog(
    ^
    Driver2.java:51: incompatible types
    found : java.lang.String
    required: int
    int val = bc.getCode();
    ^
    the case 2 in the driver is where it messes up, i believe..it works with just the case 1...any help/advice is appreciated(i am aware of spacing errors)
    import javax.swing.JOptionPane;
    import java.util.Scanner;
    public class Driver2
       public static void main(String[] args)
          String userChoice;
          int choice;
    Scanner keyboard = new Scanner(System.in);
    userChoice = JOptionPane.showInputDialog("Enter 1 to enter a numeric zip code:\n"
    + "Enter 2 to enter a bar code:\n"
    + "Enter 3 to exit program:\n");
    choice = Integer.parseInt(userChoice);
    while (choice != 3)
           switch (choice)
           case 1:
           String input = JOptionPane.showInputDialog( "Please enter a five-digit zip code: ");
    int num = Integer.parseInt(input);
    BarCode bc = new BarCode(num);
    String code = bc.getCode();
    JOptionPane.showMessageDialog(null, "The barcode of the zip is: " + code);
    System.exit(0);
    break;
    case 2:
    String code = JOptionPane.showInputDialog( "Please enter bar code: ");
    int val = bc.getCode();
    if (val >= 0)
    System.out.println("The zip code is: " + val);
    else
    System.out.println("Incorrect bar code data");
    System.exit(0);
    break;
    case 3:
    break;
    userChoice = JOptionPane.showInputDialog("Enter 1 to enter a numeric zip code:\n"
    + "Enter 2 to enter a bar code:\n"
    + "Enter 3 to exit program:\n");
       public BarCode(int n)
          zip = n;
       public String getCode()
          String barCode = "|";
          int sum = 0;
          int temp = 0;
          temp = zip / 10000;
          sum = sum + temp;
          Digit d1 = new Digit(temp);
          barCode = barCode + d1.getCode();
          zip = zip % 10000;
          temp = zip / 1000;
          sum = sum + temp;
          Digit d2 = new Digit(temp);
          barCode = barCode + d2.getCode();
          zip = zip % 1000;
          temp = zip / 100;
          sum = sum + temp;
          Digit d3 = new Digit(temp);
          barCode = barCode + d3.getCode();
          zip = zip % 100;
          temp = zip / 10;
          sum = sum + temp;
          Digit d4 = new Digit(temp);
          barCode = barCode + d4.getCode();
          zip = zip % 10;
          temp = zip;
          sum = sum + temp;
          Digit d5 = new Digit(temp);
          barCode = barCode + d5.getCode();
          temp = 10 - (sum % 10);
          Digit d6 = new Digit(temp);
          barCode = barCode + d6.getCode() + "|";
          return barCode;
       private int zip;
    public class BarCode1
       public BarCode1(int n)
          zip = n;
       public String getCode()
          String barCode = "|";
          int sum = 0;
          int temp = 0;
          temp = zip / 10000;
          sum = sum + temp;
          Digit d1 = new Digit(temp);
          barCode = barCode + d1.getCode();
          zip = zip % 10000;
          temp = zip / 1000;
          sum = sum + temp;
          Digit d2 = new Digit(temp);
          barCode = barCode + d2.getCode();
          zip = zip % 1000;
          temp = zip / 100;
          sum = sum + temp;
          Digit d3 = new Digit(temp);
          barCode = barCode + d3.getCode();
          zip = zip % 100;
          temp = zip / 10;
          sum = sum + temp;
          Digit d4 = new Digit(temp);
          barCode = barCode + d4.getCode();
          zip = zip % 10;
          temp = zip;
          sum = sum + temp;
          Digit d5 = new Digit(temp);
          barCode = barCode + d5.getCode();
          temp = 10 - (sum % 10);
          Digit d6 = new Digit(temp);
          barCode = barCode + d6.getCode() + "|";
          return barCode;
       private int zip;
    public class Digit
       public Digit(int n)
          zip = n;
       public String getCode()
          String bar = "";
          if (zip == 1)
             bar = ":::||";
          else if (zip == 2)
             bar = "::|:|";
          else if (zip == 3)
             bar = "::||:";
          else if (zip == 4)
             bar = ":|::|";
          else if (zip == 5)
             bar = ":|:|:";
          else if (zip == 6)
             bar = ":||::";
          else if (zip == 7)
             bar = "|:::|";
          else if (zip == 8)
             bar = "|::|:";
          else if (zip == 9)
             bar = "|:|::";
          else
             bar = "||:::";
          return bar;
       private int zip;
    public class Digit1
       public Digit1(int n)
          zip = n;
       public String getCode()
          String bar = "";
          if (zip == 1)
             bar = ":::||";
          else if (zip == 2)
             bar = "::|:|";
          else if (zip == 3)
             bar = "::||:";
          else if (zip == 4)
             bar = ":|::|";
          else if (zip == 5)
             bar = ":|:|:";
          else if (zip == 6)
             bar = ":||::";
          else if (zip == 7)
             bar = "|:::|";
          else if (zip == 8)
             bar = "|::|:";
          else if (zip == 9)
             bar = "|:|::";
          else
             bar = "||:::";
          return bar;
       private int zip;
    }

    > i got it to compile now...i can toy around w/
    it..thanks for the help
    Good.
    Stick with this handle, ok?I must say I am not thrilled with
    a) when I questioned the first post of WhiteSox asking if it was bugz or a classmate or what I was ignored by the OP
    b) I guess the OP is trying to distance himself from his very first thread where somebody did part of his homework for him with results that are now plainly evident. As I predicted at the end of the last thread.
    http://forum.java.sun.com/thread.jspa?threadID=703258 Reply 11
    I hope that matsabigman and others who help homework posters by doing it for them will take note of the results of this help thus far. Not much good has come of this.
    BigMan/WhiteSox I am still detecting a fundamental lack of basic concepts on your part. This is the underlying cause of your compile errors but those are only a symptom. You can continue treating the symptoms but it would be a better use of your time to treat the disease, which in this case means spending some time getting a better grasp of Java fundamentals.

  • Help with chat server

    I've been able to modify the server java application example from the Java Sun website, that accepts multiple connections but the problem now is how to send the message received from one client to all clients..
    Is there a way to access the sockets of other clients from the thread of the client who sent the message (I'm using multithreading), so that all clients receive the message that was received by the server?
    If not, would you provide a code example of how a server able to handle multiple simultaneous client connections would be able to send the message it receives from one client to all the clients. Thanks.

    The example I modified is the KKMultiServerThread ( http://java.sun.com/docs/books/tutorial/networking/sockets/clientServer.html#later ) from the All About sockets example from the Sun website tutorials. Problem is how do I access the PrintWriters for the different sockets (the different clients) (because they have different threads) when I am printing out that message to all clients within the for loop which is in the thread of the socket for the client which sent that message? That was my initial problem - I could only work with the socket of the client that sent the message (and consequently with his PrintWriter only). If I declare an array of PrintWriters in the Thread which is a different file than the main Server file which opens the server's listening port and accepts connections then the array would not be final and would change from socket to socket therefore not doing any good. It would only be accessible by each socket and would only store its own PrintWriter.. Any other ideas? And thank you very much for the help by the way .

  • Help with RX1600 plz

    Hi, I just bought a new MSI RX1600 PRO and when I installed with the driver that came with it my Windows XP shows two cards in the device manager, one R530 and one R530 Secondary??!!! Also, the 3D Mark 2005 reports the core clock to be 375 when according to the MSI site it should be 500 MHz, and the video memory speed is 0.0 MHz, does any one know whats wrong?

    Quote
    3D Mark 2005 reports the core clock to be 375 when according to the MSI site it should be 500 MHz, and the video memory speed is 0.0 MHz, does any one know whats wrong?
    Yes, 3D Mark is wrong. It is a software issue that even in 3d Mark 06 the problem remains (wrong Core clock, and wrong Memory speed). The Ram speed of my vid card is 700 MHz... 3d Mark show it as 0.0.
    Your vid card is fine. I recommend you to use Everest Home Edition, it will give you a lot information about your whole PC:  http://www.majorgeeks.com/download4181.html

  • Help with brasso plz!!!!!!!!!!!

    to put it plain and simple i would like to use brasso on my ipod but not sure how to. I mean i put it on and scrubbed it off,didnt harm the screen; but didn't seem to help it any to. Im probably doing it wrong . any help?

    I don't know, but search the forum for Brasso (near top right of this page 'more options') and you'll get a gizillion hits. Good luck.

  • Some help with sounds plz ;p

    First of all, congrats for the forum ^^ great ideas here :)
    Well, i'm working with a friend in a multiplayer space combat game (nameless nowdays) implemented with jsdk5. The game uses a thread to update each player object and then repaint a "main" jframe where all the things happen. I was trying to add sounds to the game, so after trying all sort of things i created a Sonido class, with a play(int clip) method that creates a thread whose run() method plays the clip identified by clip. Somethig like this:
            Audioclip[] sonidos;
         public static void play(int clip){
              final int c = clip;
                   Thread reproductor = new Thread(Ship2.mGrafico){
                        public void run(){
                             sonidos[c].play();
              reproductor.start();
         }Even doing that the clip only seems to sounds when i call loop() instead of play(). why? i don't know.

    Check out the bug database.
    Bug ID 5070730, 5085008, 6186076.
    They are all essentially the same bug. What it means is that JDK 1.5/1.6 does not play sounds less than 1 second. If sounds are very important to you don't upgrade until this bug is fixed (or loop until it is). If you need to use JDK 1.5 upgrade whenever there is a new version and hopefully it will be fixed soon. I wouldn't hold my breath though. ;)

  • HT4623 my iphone is not connecting to the computer so i need help with this plz

    my iphone isnt working now that i connected it to restore it to itunes and i cant even connect it

    Try to get your phone into DFU mode if you were planning on restoring anyways.
    1. Press and hold the Home button and the Sleep/Wake button at the same time.
    2. After exactly 10 seconds release the Sleep/Wake button. Continue holding the home button until you iTunes pops up a message telling you that it has detected an iPhone in recovery mode.
    NOTE***: It may take a few attempts to get your iPhone into DFU mode. Generally, I hold down both buttons then release the Home button just before I think the Apple logo would appear. If you are still holding both buttons down and you see the Apple logo you are holding them down for too long!

  • Help with MVC plz!

    I'm attempting to use Swing components to implement a MVC GUI component.
    It's quite simple, a JFrame contains a Jtree and a JButton. When I click the button I want the model of the JTree to be changed in some way. The changing of the model would then force the view to update itself. I've been trying to get this to work for a day or two and have had no luck.
    Does anyone out there have any simple examples of a simple MVC component that I could see to get a better understanding of what's going on.
    Thx

    maybe this is relevant, in javadocs for AbstractTableModel,
    fireTableStructureChanged
    public void fireTableStructureChanged()
    Notifies all listeners that the table's structure has changed. The number of columns in the table, and the names
    and types of the new columns may be different from the previous state. If the JTable receives this event and its
    autoCreateColumnsFromModel flag is set it discards any table columns that it had and reallocates default
    columns in the order they appear in the model. This is the same as calling setModel(TableModel) on the
    JTable.
    See Also:
    TableModelEvent, EventListenerList

  • How do I reset the password that allows me to download reader - I worked with chat help - we rest my password and I can get into my adobe account but when I try to download reader and work my way through the process when I get to the password it will not

    How do I reset the password that allows me to download reader.. I worked with chat help two hours last night - we have reset a password that lets me into my adobe account but in the download reader process that password will not work - where it says Adobe reader wants to change something and please type in password, just vibrates with the dots glowing purple but will not open…. what do I do to reset that password or get it to function. they would not assist me further they said its a free download and I would need to seek help from forums ( all this is new to me )
    so "forums" help…what do I do ?
    thank you
    PL

    patricia here again:
    I am the system administrator - personal computer
    I have been able with your lead to find the password I need , and to have install happen
    however - when I then go to the website to download the Pdf document I need I get a screen with the big red adobe icon that says to complete and down load this document I must launch adobe reader a dn sign the terms of agreement , close browser and reopen.
    but thatscren has no choice buttons whatsoever, I cannot find anywhere a adobe reader image to launch - been into launch pad , preferences etc.
    so now the loop is the pdf document and the adobe screen saying I must do terms of agreement
    like is this Kafka like or what ...
    suggestions?
    thanks
    P.

  • When i connect i5 to itunes .. i dont get "delete" option for songs upon right click .. can anyone help me with this plz?

    when i connect i5 to itunes .. i dont get "delete" option for songs upon right click .. can anyone help me with this plz?

    Yes, annoying. A couple of options:
    While it's playing the current A song, click on the H song to select it (but not double click to play it), when iTunes jumps to the second A song, press the down key and iTunes will remember that you had that H song selected and will move the selection to the second H song while the second A song is still playing. So, still jumps around, but easy to get back to where you were.
    Create a new playlist for your music, right click on it, select "New Window" and you can browse your music in a second list while the first window continues to play music. But if you then start playing music in that second window, you have to go back to the first window if you want to start browsing again. Not great if you're navigating around to play the next song.
    Play music from iTunes DJ, then as you're browsing around your library, you can add things to play next in DJ, and go back. You can combine this with previous suggestion, to keep DJ open in one window while you browser in the other window.
    None of these are great, but maybe one of these works better than your current workflow.

  • Plz help with my laptop

    hi i just got a powerbook g3 from my ffreind, i think its a lombard because it doesnt have those ports in the back. It has like almmost 5 gbs of space and i got 2gbs left, lol. ok back to the point: im trying to download stuff like limewire and java, but when i download the instalation thing on my laptop and i open it , a screen pops up and says that quicktime cant read this file. and now im trying to figure out what program should i start the insalatikon with? plz help me and be specific where it is located.
    Thanx
    and anyone that plays runescape say something about it. Runescaoppe rocks~~~~~~~lol

    Welcome to the world of Macintosh! Sooo much better then Windows. And of course welcome to the forums! Anyway it sounds like, since your running OS 9, you either have the file formats set wrong or Quicktime cannot play that sort of media file possibly because it doesnt have the right codecs. I suggest updating to Mac OS 9.2.2 which is free for all OS 9 users as it includes newer versions of Quicktime if you dont already have the newest version. Look under Support>Mac OS> Jaguar and Older and you'll see, on the side, Mac OS 9 support. From there you'll see Updates for OS 9 I believe. Something like that I dont remember for sure and cant check now cause im using my crappy Windows PC and it wont let me get on the support page (typical XP)

Maybe you are looking for