Multithreading server /- client doesnt update need a little help

I have three classes, one is my client called lobby, the second is my server, then my third is the server thread. Everything works but the client doesnt seem to update unless you type stuff in and hit enter or press send and that isbecause of the key and action listeners, how do i go about having to updating every 10 seconds or less..? I tried doing a while statement and of course it freezed it because its an infinite loop, tried making it a thread, not to good at that, i just need some advice on how to solve this problem, thanks.
public class Lobby extends JPanel {
     public Lobby()
          listenSocket();
          send = new JButton("Send");
          chatter = new JTextField();
          motd = new JLabel("The Lobby");
          this.setLayout(new MigLayout());
          this.setSize(800, 600);
          this.setBackground(Color.white);
          this.setAutoscrolls(true);
          this.add(motd, "span 1, align center");
          this.add(UserListTop(), "align center, wrap");
          this.add(ChatBox(), "");
          this.add(UserList(), "wrap");
          this.add(Chatter(), "");
          this.add(Send(), "");
          this.setVisible(true);
     public Component ChatBox()
          Dimension dscroll = new Dimension(590, 400);
          chatbox = new JTextArea(20, 50);
          chatbox.setLineWrap(true);
          chatbox.setEditable(true);
          chatbox.setWrapStyleWord(true);
          JScrollPane areaScrollPane = new JScrollPane(chatbox);
          areaScrollPane.setVerticalScrollBarPolicy(
                    JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
          areaScrollPane.setAutoscrolls(true);
          areaScrollPane.setPreferredSize(dscroll);
          return areaScrollPane;
     public Component Chatter()
          KeyListener enter = new KeyListener()
               @Override
               public void keyPressed(KeyEvent event) {
                    if((event.getKeyChar() == KeyEvent.VK_ENTER) && (chatter.getText() != "") && (chatter.getText() != null))
                         //Send data over socket
                         String text = chatter.getText();
                         out.println(text);
                         chatter.setText(new String());
                         //Receive text from server
                         try{
                              String line = in.readLine();
                              chatbox.append("Usernamehere: " + line + "\n");
                         } catch (IOException e){
                              System.out.println("Read failed");
                              System.exit(1);
               @Override
               public void keyReleased(KeyEvent e) {
               @Override
               public void keyTyped(KeyEvent e) {
          String line;
          try {
               line = in.readLine();
               chatbox.append("usernamehere: " + line + "\n");
          } catch (IOException e1) {
               // TODO Auto-generated catch block
               e1.printStackTrace();
          chatter.addKeyListener(enter);
          Dimension chattersize = new Dimension(590, 30);
          chatter.setPreferredSize(chattersize);
          chatter.setVisible(true);
          return chatter;
     public Component Send()
          ActionListener sendl = new ActionListener()
               @Override
               public void actionPerformed(ActionEvent event) {
                    Object source = event.getSource();
                    if(source == send){
                         //Send data over socket
                         String text = chatter.getText();
                         out.println(text);
                         chatter.setText(new String(""));
                         //Receive text from server
                         try{
                              String line = in.readLine();
                              System.out.println("UserNameHere: " + line);
                              chatbox.append("Usernamehere: " + line + "\n");
                         } catch (IOException e){
                              System.out.println("Read failed");
                              System.exit(1);
          send.addActionListener(sendl);
          send.setVisible(true);
          return send;
     public Component UserListTop()
          JLabel userlisttop = new JLabel("Players");
          return userlisttop;
     public Component UserList()
          Dimension scrollsize = new Dimension(170, 400);
          String names[] = new String[1500];
          for(int i = 0; i < 1500; i++)
               names[i] = "Player" + i;
          userlist = new JList( names );
          userlist.setBackground(Color.white);
          userlist.setSize(50, 200);
          JScrollPane userlistscroll = new JScrollPane(userlist);
          userlistscroll.setPreferredSize(scrollsize);
          return userlistscroll;
     public void listenSocket(){
          //Create socket connection
          try{
               socket = new Socket("localhost", 4444);
               out = new PrintWriter(socket.getOutputStream(), true);
               in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
          } catch (UnknownHostException e) {
               System.out.println("Unknown host: localhost");
               System.exit(1);
          } catch  (IOException e) {
               System.out.println("No I/O");
               System.exit(1);
}

3rd class
package server;
import java.io.DataInputStream;
import java.io.IOException;
import java.io.PrintStream;
// This client thread opens the input and the output streams for a particular client,
// ask the client's name, informs all the clients currently connected to the
// server about the fact that a new client has joined the chat room,
// and as long as it receive data, echos that data back to all other clients.
// When the client leaves the chat room this thread informs also all the
// clients about that and terminates.
import java.net.Socket;
public class clientThread extends Thread{
    DataInputStream is = null;
    PrintStream os = null;
    Socket clientSocket = null;      
    clientThread t[];
    public clientThread(Socket clientSocket, clientThread[] t){
     this.clientSocket=clientSocket;
        this.t=t;
    public void run()
     String line;
        String name;
     try{
         is = new DataInputStream(clientSocket.getInputStream());
         os = new PrintStream(clientSocket.getOutputStream());
         os.println("Enter your name.");
         name = is.readLine();
         os.println("Hello "+name+" to our chat room.\nTo leave enter /quit in a new line");
         for(int i=0; i<=9; i++)
          if (t!=null && t[i]!=this)
          t[i].os.println("*** A new user "+name+" entered the chat room !!! ***" );
     while (true) {
          line = is.readLine();
if(line.startsWith("/quit")) break;
          for(int i=0; i<=9; i++)
          if (t[i]!=null) t[i].os.println("<"+name+"> "+line);
     for(int i=0; i<=9; i++)
          if (t[i]!=null && t[i]!=this)
          t[i].os.println("*** The user "+name+" is leaving the chat room !!! ***" );
     os.println("*** Bye "+name+" ***");
     // Clean up:
     // Set to null the current thread variable such that other client could
     // be accepted by the server
     for(int i=0; i<=9; i++)
          if (t[i]==this) t[i]=null;
     // close the output stream
     // close the input stream
     // close the socket
     is.close();
     os.close();
     clientSocket.close();
     catch(IOException e){};

Similar Messages

  • Need a little Help with my new xfi titanium

    +Need a little Help with my new xfi titanium< A few questions here.
    st question? Im using opt out port on the xfi ti. card and using digital li've on a windows 7 64 bit system,? I would like to know why when i use 5. or 7. and i check to make sure each speakear is working the rear speakers wont sound off but the sr and sl will in replace of the rear speakers. I did a test tone on my sony amp and the speaker are wired correctly becasue the rear speakers and the surrond? left and right sound off when they suppose too. Also when i try to click on? the sl and sr in the sound blaster control panel they dont work but if i click on the rear speakers in the control panel the sl and sr sound off. Do anyone know how i can fix this? So i would like to know why my sl and sr act like rears when they are not?
    2nd question? How do i control the volume from my keyboard or from windows period when using opt out i was able to do so with my on board? sound max audio using spidf? Now i can only control the audio using the sony receiver.
    Thank you for any help..

    /Re: Need a little Help with my new xfi titanium? ?
    ZDragon wrote:
    I'm unsure about the first question. Do you even have a 7. system and receiver? If you just have 5., you should be able to remap the audio in the THX console.
    I do have a sony 7. reciever str de-995 its an older one but its only for my cpu. At first i didnt even have THX installed because it didnt come with the driver package for some reason until i downloaded the daniel_k support drivers and installed it. But it doesnt help in anyway.
    I have checked every where regarding the first question and alot of people are having problems getting sound out of there rear channels and the sound being re-mapped to the surround right and the surround left as if there rear left and rear right.
    I read somewhere that the daniel_k support drivers would fix this but it didnt for me and many others.
    For the second question i assumed it would be becasue of the spidf pass through and that my onboard sound card was inferior to the xfi titaniums. But i wasnt sure and i was hopeing that someone would have a solution for that problem because i miss controlling the volume with my keyboard.

  • Need a little help with syncing my iPod.

    I got a new macbook pro for cristmas and a few cds. After i tried to sync my ipod to itunes i put a symbol next to each song that i got from other cds saying that they were downloading but they werent. Also the cds i downloaded to my ipod for the first time didnt appear at all. Need help.

    /Re: Need a little Help with my new xfi titanium? ?
    ZDragon wrote:
    I'm unsure about the first question. Do you even have a 7. system and receiver? If you just have 5., you should be able to remap the audio in the THX console.
    I do have a sony 7. reciever str de-995 its an older one but its only for my cpu. At first i didnt even have THX installed because it didnt come with the driver package for some reason until i downloaded the daniel_k support drivers and installed it. But it doesnt help in anyway.
    I have checked every where regarding the first question and alot of people are having problems getting sound out of there rear channels and the sound being re-mapped to the surround right and the surround left as if there rear left and rear right.
    I read somewhere that the daniel_k support drivers would fix this but it didnt for me and many others.
    For the second question i assumed it would be becasue of the spidf pass through and that my onboard sound card was inferior to the xfi titaniums. But i wasnt sure and i was hopeing that someone would have a solution for that problem because i miss controlling the volume with my keyboard.

  • Need a little help new to mac

    Need a little help I'm new to Mac.. i have had my ibook for over a year now and i like it a lot, but some times my usb post dies on my for a couple days maybe weeks. Ill have my ipod connected and when i go to plug in a flash drive. It doesn't detect my ipod anymore and my usb port don't work. it says that they were "removed improperly" and now they are not working again..i have tried to reinstall the whole os again and that doesn't work i don't have the hardware test disk so i don't know what could be the problem i know its not the logic board is there any test i can do to it to find out the problem its an ibook late 2001... there is no reset button on it. i tried to hold in the space bar and now when i boot up i get prompt to this screen that shows the world and then a folder with a ? mark but then after a few sec it boots right up im a mess need some help

    +it says that they were "removed improperly"+
    You have to go to the iPod's icon on your computer (or the flash drive's icon), select it and eject it there before removing it. Otherwise, data can be corrupted and/or lost. Repeatedly removing it without ejecting it from the desktop can cause it not to be recognized any longer.
    If your iBook is a "late 2001" model. It should have a reset button. Check out the chart here to make sure which model iBook you have:
    http://support.apple.com/kb/HT1772?viewlocale=en_US
    +i get prompt to this screen that shows the world and then a folder with a ? mark but then after a few sec it boots right up+
    It's trying to find a network volume from which to boot.
    Once it's booted up, go to System Preferences > Startup Disk, and select your Mac OS X startup volume. Then close System Preferences. The next time you start up, it should start up without looking for a network volume.

  • Greetings,   I need a little help. I have a WRT54G Wirele...

    Greetings,
    I need a little help. I have a WRT54G Wireless Router, and it worked well for years with my Alcatel DSL Modem (Bellsouth/ATT).  The modem went out and it was replaced with Westell Modem.  When I bypass the router I have no problem connecting to the Internet, however when I connect the router--no connection.  I thought it would not be a problem swapping the modem out.  I am running XP with Norton Internet Security and Anti-virus.  I have disabled Norton and do not believe that to be the problem.  Do I have to reconfigure the router?  If so, can I do it with the original install CD?  (I am disabled and the original CD/instructions/box is in the attic and I cannot get it easily.)  I have read several different threads, but they do not specifically address my problem.  Any assistance is appreciated.  Eddy

    Many Westell modems are actually "modem-routers" and they use the same 192.168.1.1  address space as your WRT54G.  This is the root of your problems.
    Try the settings at this URL.
    http://www.dslreports.com/faq/6323
    Note that the "WAN" port on the BEFSR41 in the example is the same as the "Internet" port on your WRT54G.
    Please let me know whether or not this worked for you.

  • Need a little help with dial setup on CME

    I've got a CME I'm using for testing and I think I need a little help figuring out the proper config to get the system to accept numbers I dial and have those numbers be passed on to an Avaya system (including the leading 9 for ARS in Avaya) via H.323 IP trunks.   I have it working well for internal 5 digit extension calls across the H.323 trunks and I also have it working well for some types of outside calls that gets passed on to the Avaya and then the Avaya dials the call out to the PSTN.   My only real problem is, I can't figure out how to correctly configure CME to examine the digits I'm dialing and only send the digits once I'm finished dialing....not as soon as it sees an initial match.
    What's happening is this.  I can dial local numbers in my area as 7 digits or 10 digits.  The phone company doesn't yet force us to dial area code and number for local calls (10 digits).  I can still dial 7 digits.   But...if I put an entry in CME that looks like this....
    (by the way, the 192.168.1.1 IP is not the real IP address, that's just an example, but the rest of this entry is what I really have entered in CME)
    dial-peer voice 9 voip
    description Outside 7 Dig Local Calls Via Avaya
    destination-pattern 9.......
    session target ipv4:192.168.1.1
    dtmf-relay h245-alphanumeric
    no vad
    ...Then it will always try to dial out immediately after seeing the first 8 digits I dial (9 plus the 7 digit number I called)...even though I have a speicifc entry in the system that accounts for calls to 9 plus area code 513.  I would have assumed that if I put the specific entry in for 9513....... it would see that and wait to see if I was actually dialing something to match 9513....... instead of 9.......   Understand what I mean?   Because 9513....... is more specific than 9....... but it still tries to send the call out immediately after seeing the first 8 digits I dialed.
    dial-peer voice 9513 voip
    description Outside 10 Dig Local Calls Via Avaya
    destination-pattern 9513.......
    session target ipv4:192.168.1.1
    dtmf-relay h245-alphanumeric
    no vad
    ...BUT...here's the interesting thing.  If I trace the 10 digit call in Avaya, I see that the number being presented to the Avaya PBX is only the first 7 digits of the number....not the full 10 digits...BUT I see a few more of the digits I dialed (like the 8th and 9th digits) after the call is already setup and sent to the PSTN.  It's like the CME is trying to send the rest of the 10 digits I dialed, but at that point it's already too late.   It setup the call as a 7 digit call (9 plus 7 digits), not 10 digit like I wanted.
    I'm more familiar with how to setup dialing in the Avaya via ARS.  My background is Avaya, not Cisco, so this dial-peer config is a little difficult for me until I understand the reasoning of how it examines the numbers and what I should do to make it wait for me to finish dialing....or to tell the system that what I'm dialing will be a minimum or a certain amount of digits and maximum of a certain amount of digits, like the Avaya does.  I just need some pointers and examples to look at :-)   I think I've almost got it....but I'm just missing something at the moment.
    Just so you understand, the call flow should be like this:  Cisco phone registered to CME > CME to Avaya via H.323 trunks > Avaya to PSTN via ISDN PRI trunks connected to Avaya.  I have to be sure I send the 9 to the Avaya also, because 9 triggers ARS in the Avaya. 
    Thanks for your help

    Here is a good document that explains how dial-peers are matched in the Cisco world:
    http://www.cisco.com/en/US/tech/tk652/tk90/technologies_tech_note09186a008010fed1.shtml#topic7
    In your case, it is variable length dial plan you are trying to implenent. To fix it, you need to add a T to force the system to wait for more digits to be entered if there is any.
    dial-peer voice 9 voip
    description Outside 7 Dig Local Calls Via Avaya
    destination-pattern 9.......T
    session target ipv4:192.168.1.1
    dtmf-relay h245-alphanumeric
    no vad
    dial-peer voice 9513 voip
    description Outside 10 Dig Local Calls Via Avaya
    destination-pattern 9513.......
    session target ipv4:192.168.1.1
    dtmf-relay h245-alphanumeric
    no vad
    You can also configure the inter-digits timeout using the command timeouts interdigit under telephony-service.
    Please rate helpful answers!

  • Need a little help.... not major....but am unsure I have...

    Need a little help.... not major....but am unsure I have the 2.4 GHz Wireless-G Broadband Router Model WRT54G version 2 I had bought some time ago (over year and a half) and never really had it hooked up since I have been moving from place to place. Now that I'm retired and staying in one place I'm ready to set up. I find myself having "several" power adaptors and not sure which is the correct one. Can anyone tell me if all the broadband routers had the Linksys name and/or logo on them? None of the adapters I have do. I want to use a proper adapter so as not to damage....are there any specs that would be helpful so that one of these adapters would work? Also I'm running WindowsXP Sorry to bother you folks with a dumb question as I'm sure there are others with far more important questions and concerns. Although I can't tell other than the end going into the unit fits, I do have one Class 2 Transformer which might be the one it's about 1 1/2 inches thick, about 2 inches tall with following written information: Model 49-12-1000D CUI Inc Input AC 120V 60Hz 20W Output DC12V 1000mA Appreciate any help you can give.....I believe my unit is an older one based on version so there may have been a "fatter" adapter then than now.

    The power adapter output should be 12V, 0.5A(so 6W power rating)

  • Need a little help please    Airport Express

    Need a little help please.
    I am trying to set up a wireless network at my home using Airport Express.
    I have a regular phone line running in to I assume the modem. From there, there is an Ethernet cable running from that box to the back of the PC. My question is, I think, which of those do I unplug and plug into the Airport Express, the one on the back of the PC or the one that is in the back of the modem, or is this totally wrong.
    Any help would be appreciated…
    Thanks
    In advance…
    PS I have the manual but to me it is not very clear…

    Your connection sequence would look like this:
    Internet > Modem > AirPort Express >>>wireless to your computers.
    This means that you would unplug the cable that is now connected at the back of your PC and move that connection to the AirPort Express.
    Open Macintosh HD > Applications > Utilities > AirPort Utility
    Click Continue to follow the guided setup. On the third page, you will choose the option to "Create a wireless network" and continue the setup.

  • Quality Playback-.need a little help

    Quality Playback….need a little help
    I’ve posted in the Premiere forums too, because I’m not sure where my issue is in converting .MOD files, the export of edited footage from Preimere Pro CS4 or if it’s in Encore.
    The quality just does not seem that good, I know it’s not HD quality, but it should be better than what I have.  Seems over pixilated especially around objects.
    Here’s my steps
    Convert .MOD files using Mpeg Streamclip to a .DV file format
    Settings Compression DV (DV25)
    Standard NTSC 720 x 480 29.97 fps
    Aspect 16:0
    Everything else is default
    Import to Premiere Pro CS5
    Edit footage
    Export to quicktime .mov file
    NTSC DV Widescreen
    720 x 480 quality 100%
    codec is DV25 NTSC
    Import .mov files to Encore CS5
    Build menus and playlists
    Export with default settings approximately 1hr 45min of edited video
    Thanks
    MAB

    Bill
    Thanks for your help and patience.
    I posted a screen shot of the mov export settings I was using.  I’m going to try Ann’s conversion method on the mod files to see if that improves things.
    You asked about the Encore transcoding, what do you mean by that, are there other settings in Encore that I need to set?
    I have an 1hour 45 min of video in my Encore project, burning to a 4.7 DVD.  Encore says it’s using 3.3bg, which seems low.
    MAB

  • I need a little help

    hi i need a little help making a java applet rpg with log-in, chat, etc. and i dont really know to much about it and dont understand applet programming too much. If anyone could help, it would be appreciated. Also, since i am fairly decent at making/improving websites, if you help me i could make a website for you or improve one you already have. You can email me if you want to help at "[email protected]"

    Don't just give up. Like I said, start small.
    I've never heard of any pre-made RPG java classes.
    Why don't you poke around on SourceForge or some java-centric project site or one of the java gaming sites. Maybe someone has written all these libraries already, although you may have trouble using these classes if you're not familiar with programming in general and java in particular. Or do a Google search.
    But using a specialized API is a lot easier if you know how to use the general API (i.e., j2se).
    Another option of course is not to use java at all. Many commercial games come with an editor; you may find it easier to get one of those and do a mod.

  • Need a little help with G3 Clameshell...Please

    I just received this Clameshell, and it only has OS9 on it, I haven't used 9 in forever, and really need to get OSX on it. I have retail Panther cd's. But I hear I need to update the firmware, if it isn't updated yet.
    I know I can find out which I have in System Profiler, but I can't find it in there. Is it called something else? What part of System Profiler is it in(in OS9).
    Also, I have Cable net, this Clamshell was always used with dial up, how can I switch things around in it so I can hook up my ethernet cable and run with it? Is that possible with OS9? Or will I have to update the firmware a different way.
    I am stuck. Need lots of help.
    Thanks!!!
    veganjustice

    Is it called something else? What part of System Profiler is it in(in OS9).
    It is in the field called "Boot ROM".
    ...how can I switch things around in it so I can hook up my ethernet cable and run with it?
    Open the TCP/IP control panel. Configure it to use Ethernet and DHCP to get an IP address.

  • New to mac.. need a little help

    I am relatively new to macs and need a lil help understanding what's going on with my computer. I recently got a lend of a powerbook G4 from a friend and it has a tendency to freeze up completely and I have to just hold the power button until it turns off then it when I turn it back on it will work ok again sometimes for several hours without a hitch.
    Also, sometimes instead of freezing up I'm just not able to type. I can do everything else with the mouse or open programs and such but when I try to type it just doesn't work (and again, restarting fixes the prob).
    Looking for help .. if anyone knows why it may be doing this and/or how to fix it your help would be greatly appreciated. Thanks

    Welcome to the Apple discussions.
    First, check your hard drive free space. Click on the apple on the menu bar, about this mac, ata, and click on the hard drive under ata bus (DVD drive is listed there too). That will tell you the drive capacity and how much is available. You want 10% to 15% of the total capacity to be available for systems usage. If less than that, performance can slow to a crawl, and some of the issues you identified could be due to low free disk space.
    Next, you should have a backup of the hard drive, if there's anything you want to keep.
    Download the program OnyX from http://www.titanium.free.fr/pgs2/english/download.html . Run the tasks on the cleaning and maintenance tabs. A number of people have found this helps clean up the hard drive and contributes to improved performance.
    This FAQ has some good advice for performance tuning: http://www.thexlab.com/faqs/performance.html
    If, after cleaning your system and tuning it up, you're still having problems, please post back with specifics.

  • CC Client kriegt updates nicht installiert / CC Client doesnt update properly

    Hi,
    jedes mal wenn ein update für den CC Client zur Verfügung steht und ich das update starte wird die Datei zwar runtergeladen, aber die Installation schlägt jedes mal fehl. So langsam nervt es mich nen bischen das so eine simple Sache wie ein update nicht funktioniert und ich jedes mal manuell den Client deinstallieren und wieder installieren muss.
    Ist das ein bekanntes Problem? Woran kann es liegen?
    Hi,
    every time when a update for CC Client is avaible and i start the update the installtion fails at the end. I´m kind of f**** up to uninstall and reinstall CC Client manually every time.
    Is this a known problem? What could be the reason for this?
    System:
    Win 7
    I5 2500K
    8Gb RAM
    Nvidia GTX 560 Ti
    [URL=http://www.pic-upload.de/view-22276810/Unbenannt1.jpg.html][IMG]http://www7.pic-upload.de/thumb/15.02.14/i3nkcsfkln4s.jpg[/IMG][/URL]

    http://forums.adobe.com/community/download_install_setup/creative_cloud_faq has links about update problems

  • New to the Mac and need a little help!

    I recently upgraded our pc in the house to windows vista. Before the upgrade I could use remote desktop to access the files on a shared drive. Now I cannot. Any help would be appreciated.
    I am using a mini Mac with 10.4.9 on a 1.873 core duo mini.
    Using remote desktop on XP allowed me to access and move files from a shared D:\ drive that Vista will not allow me to see. HELP??? the drive used to be accessible through the finder.

    Welcome to the Apple Discussions!
    I'm a little confused, are you running the Microsoft Remote Desktop Connection software on your Mac mini under Mac OS X? So, after the upgrade to the PC, the Mac mini can no longer connect with the same software? So your question is actually about how to re-configured Windows Vista settings so the drive is available again to the Mac client?
    -Doug

  • Using sample XML file from technical specifications, need a little help

    Hello,
    I copied and pasted the item text from the sample in the Apple technical specification. But there are a couple of places where I'm not clear what to change. I have a .M4V video file that I'm trying to podcast.
    Where it says "length" I don't know what it's looking for, I already entered a "duration" just below. Also, what would be the correct term for "type" for a .M4V video file?
    Then, there is the "guid" number and the actual file name as it is at the website. Can I make up any guid number, or does there have to be something at the site also called this, like the video file, which already has a name....confused.
    Thanks,
    TW
    BOXX Windows XP Pro

    Okay, I figured out what those entries needed to be, but I'm still not getting iTunes to recognize the feed.
    When I put the text file on the server, what do I call it so iTunes finds it?
    TW

Maybe you are looking for