Having trouble listening and writing to a socket

I might as well just post my classes. What I really need is a comprehensive guide to reading and writing to a socket. The sockets aren't being printed, and I know it's because they hang on the "readline()" statements in the netcheck functions. Why do they hang?
===================================================================
package TerminalChat;
import java.io.*;
import java.net.*;
public class QOTDServer {
     private ServerSocket serversock;
     private Socket spawnsock;
     public QOTDServer()
          // Establishes a new server socket on port 5005
          try
               serversock = new ServerSocket(5005);
          catch (IOException e01)
               System.out.println("Error: " + e01);
               System.out.println("server socket establishment stage error");
          // Untill the program is closed it will always wait untill the "ServerSocket" is accepted.
          // Once accepted, it will create a "Socket".
          while(true)
                    try
                         System.out.println("Before connect");
                         spawnsock = serversock.accept();
                         System.out.println("After connect");
                         new Thread(new ConnectionSpawn(spawnsock)).start();
                    catch(IOException e02)
                         System.out.println("Error: " + e02);
                         System.out.println("socket accept stage error");
     public static void main(String[] args)
          // TODO Auto-generated method stub
          new QOTDServer();
===================================================================
package TerminalChat;
import java.io.*;
import java.net.*;
public class ConnectionSpawn implements Runnable {
     Socket connSpawnSocket;
     BufferedWriter buffwrite;
     BufferedReader buffread;
     public ConnectionSpawn(Socket sock)
          connSpawnSocket = sock;
     public void run()
          try
               buffread = new BufferedReader(new InputStreamReader(connSpawnSocket.getInputStream()));
               buffwrite = new BufferedWriter(new OutputStreamWriter(connSpawnSocket.getOutputStream()));
          catch(IOException e01)
               System.out.println("Error: " + e01);
               System.out.println("bufferedread/bufferedwrite reference to member stage error");
          this.broadcast("hello Client");
          System.out.println("Testclient: " + netcheck());
     public String netcheck()
          String msg = "No messages";
          try
               msg = buffread.readLine();
               System.out.println("post readline check");
          catch(IOException e02)
               System.out.println("Error: " + e02);
               System.out.println("netcheck stage error");
          return msg;
     public void broadcast(String message)
          try
               buffwrite.write(message);
          catch(IOException e03)
               System.out.println("Error: " + e03);
               System.out.println("ConnectionSpawn write error stage error will this make it to the terminal?");
===================================================================
package TerminalChat;
import java.net.*;
import java.io.*;
public class Client {
     Socket clientSocket;
     BufferedWriter buffwrite;
     BufferedReader buffread;
     public Client()
          try
               clientSocket = new Socket("127.0.0.1", 5005);
          catch(Exception e01){}
          try
               buffread = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
               buffwrite = new BufferedWriter(new OutputStreamWriter(clientSocket.getOutputStream()));
          catch (Exception e02)
               System.out.println("Error: " + e02);
               System.out.println("bufferedread/bufferedwrite reference to member stage error");
          this.broadcast("Hello Server");
          System.out.println("Testclient: " + netcheck());
     public String netcheck()
          String msg = "No messages";
          try
               msg = buffread.readLine();
               System.out.println("post readline check");
          catch(IOException e02)
               System.out.println("Error: " + e02);
               System.out.println("netcheck stage error");
          return msg;
     public void broadcast(String message)
          try
               buffwrite.write(message);
          catch(IOException e03)
               System.out.println("Error: " + e03);
               System.out.println("broadcast check error");
     public static void main(String[] args)
          // TODO Auto-generated method stub
          new Client();
}

Oh yea, I just forgot to flush :)
Everything's fine now - works great. BTW, do you guys
reccomend keeping a socket, or just creating a new
one every time you want to send information?Now why would you want to create a new Socket everytime.From the server once a Sockets bounds to the port you stick by it receive the desired clients.From the client side once a socket establishes a connection with the other host you can keep that socket alive till you carry out the task that you want to and then once you are through close the connection.

Similar Messages

  • Having Trouble Copy and Pasteing Local Variable in LabVIEW 2010

    I am Having Trouble Copy and Pasteing Local Variable in LabVIEW 2010 in s subVI.
    I have a VI that has a Local Variable called "Node Addr". I can select it OK, and it appears to Copy OK, But when I go to paste it, nothing appears. It doesn't matter if I use Cntrl-C Cntrl-V or the Copy and Paste from the Edit menu, I get the same results. I tried many times and got the same results. I made sure that I had click a paste location. I can insert the Local Variable if I use the Data Communication panel.
    On one of the Paste, I got an error in the error list that said that a Local Variable was not connected to anything. When I clicked on the error, it took me to an insible item in the lower right corner of the block diagram that had nothing but a select box around it. I couldn't select the invisible item, but I could delete it.
    Why does the copy and paste of this local variable not work?
    Why does the paste cause the insertion of an invisible item?

    dbaechtel wrote:
     My VI is fairly complicated. In several places in the VI, I am either reading or writing to this variable which is an numeric Indicator on the Front Panel. Using local variables seems to be the best way to handle this situation rather that using wiring all over the VI. Since the VI is mainly a State Machine and there are only 2 Writes to the local variable, I am not afraid of race conditions in this case.  NO!! While you may think that using Locals is your solution to wiring, it is not!  The fact that you are writing and reading, most likely from several places, will most definitely contribute to a race condition.  Depending on your implemetation, you should ALWAYS use wires.  The wires are the variable.  If you are using a loop (While, For), then using shift registers are appropriate means for routing values so that they are used by other sections of the code, later.  One thing you must respect with LabVIEW is the dataflow.  That's where Locals often fail.
    I am not copying the Local Variable from one VI to another.
    I am not copying the Local Variable from one VI to another.
    The Data Communication panel is one of the panels that shows up in the Functions pop up list when editing the Block Diagram. It is the panel that includes the Local Variable function.
    I don't know if the invisible item that was inserted in my block diagram was hidden or not. All I know is that the Errors List said that it was a Local Variable and that it was not connected to anything. I couldn't select it to get more information. All I could do was delete it.
    You did not address my questions about why the Copy and Paste does not work properly for my Local Variable.  Maybe it's a sign from the Software Gods not to use them LOL!..
    So if I understand correctly, you are trying to copy & paste the Local Variable from within the same VI.  How large is your block diagram?  Did you try right-click on the variable and select "Find > Local Variables"?  If it's a block diagram larger than 1 single screen (which it shouldn't), then it is possible that the Local is hiding beyond the screen.  You should find it as I described earlier.
    See my comments in red above.

  • I am having trouble bouncing and creating an aiff file that plays back. I've checked my output settings, and although I am able to create MP3s, the aiffs are blank. The happens when I try to export a track as an aiff file - it's blank.

    I am having trouble bouncing and creating an aiff file that plays back. I've checked my output settings which appear to be correct. Although I am able to create MP3s, the aiffs are blank. The happens when I try to export a track as an aiff file - it's blank.

    When bouncing, do you use the Key Command or the button on the Output Channel Strip? The Key Command only bounces from the Stereo Output. The bounce button bounces from the Channel Strip it is on. So if you want to bounce out outputs 3-4 or higher, don't use the key command, but the button.
    The strange thing here is that Logic, when it bounces an MP3, first bounces an AIFF, which at the end of the bounce process is being converted to MP3, so I can't imagine how you can get a silent AIFF and a normal MP3.
    How have you listened to those bounces? iTunes? Quicklook? Quicktime?

  • I am having trouble printing  and am only getting part of the document which i have no margins set any help??

    i am having trouble printing  and am only getting part of the document  i have no margins set any help??

    What version of Pages?
    What Printer?
    If it is Pages '09, turn Comments off.
    Peter

  • Having trouble downloading and installing Premiere Elements 10 from my account.

    Having trouble downloading and installing Premiere Elements 10 from my account.

    Hi Jeff,
    Thanks for your reply.
    Here’s what I downloaded from my account – PremiereElements_10LS_15_win64
    I do get an error message when I double click to install:
    “The file archive part of Adobe Premiere Elements 10 is missing.
    You need all parts in the same folder in order to extract Adobe Premiere Elements 10.
    Please download all parts”.
    When on the Adobe site there are many choices which is confusing.
    Please direct me to the correct one….
    I’m running Windows 8.1
    Thank you George

  • Having trouble downloading and installing iTunes to my pc Windows 7

    I am having trouble downloading and installing iTunes to my PC with Windows 7.   I have been trying for 4 hours and can't get it to download.  Any suggestions?

    Do you get an error message when you try to install iTunes? If so, what does it say? (Precise text, please.)

  • Since Mavericks was installed I amd having trouble streaming and the fan kicks in and stays on when I am watching stream in features

    Since I installed Mavericks I am having trouble streaming and the fan turns on and stays on shortly into watching a film on line.
    Also the screen breaks up  into lines and colors with no image in the middle of viewing a film sometimes several tomes.

    Hi Mudra,
    Thanks for visiting Apple Support Communities.
    If your fan is running and you're noticing video issues when streaming video, I'd suggest first trying to reset your system, as described in this article:
    Apple computers: Troubleshooting issues with video on internal or external displays
    http://support.apple.com/kb/ht1573
    Reset the system
    You can reset the Mac's parameter RAM and SMC.
    All the best,
    Jeremy

  • I am having trouble downloading and updating apps. I get a message "Error 1004 try again later" has anyone experienced this?

    I am having trouble downloading and updating my apps for my IPad2. I am getting a messahe "Error 1004 try again later". Anyone experienced this?

    Hi John
    iTunes Support wasn't of any use to me.
    I have also been having another problem - with BBC iPlayer and other video streaming not working due to insufficient bandwidth, despite my overall download speed being consistently around 50Gb.  This is also affecting AppleTV downloads
    I am using Virgin Media as my ISP, and was wondering whether you do as well.  This might be the common thread.
    -Bernard

  • Having trouble Audio and Video Syncing on iTune

    Having trouble Audio and Video Syncing on iTune anyone know how to repair?

    Here are two suggestions:
    If everything is pretty much in sync until 17 minutes in, do a re sync every ten minutes.  This should ensure that, even if the sync drifts by a few frames over 10 mins, the video will not seem distinctly out of sync at any time.
    Another approach would be to do an overall re-sync in QuickTime Pro (which I believe is part of the FCP package).
    You would need to use QTPro to trim,the video file to remove any surplus seconds of material at the beginning and end.  Then open the audio file in QT Pro and trim that if necessary.  It may be a slightly more complicated to do this at the beginning because, if the audio does not come in immediately, you'll need to make sure that you have the right amount of silence at the start of the file to match the video before the audio begins. This should leave you with video and audio files of the same length.
    Then, in the drop menus of your QT, select and copy the audio track.  Switching to the QT video file, in the drop down menus, click on add track. 
    Hope one or other of these May be some help to you.

  • I am having trouble installing and updating apps?

    I am having trouble updating and installing new apps.  Please help.

    Try here:
    Can't connect to the iTunes Store
    However, it may be an Apple server problem since other have posted with the same problem.

  • Having trouble booting and general usage

    So I've got an intel iMac running Windows 7 Professional and 10.6 The computer will randomly stop working while I'm using either OS, just kind of freeze for a few seconds to minutes and then all of a sudden will act responsive again. So I tried reinstalling both OS' and still having trouble. Before and after the reinstalls the boot menu (holding alt) will show no drives, but will show a bootable cd if I have one in there.
    I work in IT for a relatively large campus and I've seen my fair share of viruses and the like, and I don't think the problem is in software. Could there be an issue with the EFI firmware reading the disks? This doesn't seem likely as the OS X install disk will sometimes show the Hard drive in disk utility, and other times not. I'm thinking its either a loose cable, or a dying hard drive. Thoughts?

    If you want to check the HD you can run Apple Hardware Test in extended mode. You can find out how at: http://support.apple.com/kb/HT1509 If the system finds some errors please reproduce the error codes here.

  • I'm having trouble sending and receiving imessages to certain iphones, what changes do I need to make?

    I'm having difficulties send and receiving Imessages to certain iphones, while sending and receiving imessages from other phones

    troubleshooting message http://support.apple.com/kb/ts2755
    Are you sure the problem isn't on their end and not yours.

  • Having trouble listening to podcast......suddenly

    Windows XP
    can anyone help?
    after listening to a podcast daily, suddenly i get the following prompt when trying to download the last show, or any show for that matter:
    "There was a problem downoading "FTL2006-03-07". You do not have any access privileges for this operation.
    Please check that the URL is correct and the connection to the network is active and try again."
    Well, the URL is correct, for I unsubscribed and resubscribed to the podcast. Any help would be appreciated.
    I'm still waiting on btabz for some help with another problem that unfortunately, he made worse...sorry.
    thanks
    Windows XP
    Windows XP
      Windows XP  

    I was never having a direct conversation with you and never learned the specifics of the problem. My messages were replies to someone named csshawke. That's why it is better to create your own thread, to try to keep everything nice, organized, and working No worries though
    Do you know where the iTunes Music Library.xml file is? Not what your iTunes library looks like or what is in it, but where that file is? Your music is still on your computer, iTunes just isn't showing it. Just, do you know where that file is? That file tells iTunes where to look. If you have it, you are fine.
    btabz

  • Why is my mid-2010 macbook pro having trouble booting and crashing?

    I have a mid-2010 13 inch macbook pro that has recently began to have severe problems. It started after I shut it down one night and woke up to the sound of my mac's fans running loudly and my computer running extremely hot. Apparently, it must not have finished shutting down that night and something went wrong with it when i closed the lid. Ever since then, the computer will either take a long time to boot up (the apple symbol will take up to a minute to appear, and then up to several more minutes to go to my desktop) or it will display an error (either the folder icon appears instead of the apple logo, or the apple logo appears and then after a minute or two is replaced by the circle slash). Once i'm in, the computer seems to function normally, but anytime it needs to access the disc there might be another delay, or the computer will freeze, forcing me to shut it down again. The most common time this occurs is when I am waking the mac from sleep. In addition, the cpu would run hot (~85) which would imply i was doing high cpu activity, except i was usually doing very little, activity monitor showed low levels with sudden intense spikes whenever i did something.
    I've run several diagnostics to try and determine the problem, but none identified an error:
    booting computer from different computer/startup disk - runs fine (apparently. gave my mac to someone else to try this test, could not see results for myself)
    Thorough Apple hardware test: no problems found
    disc utility: disc/discpermissions verified and repaired with no issue.
    PRAM/VRAM reset: actually sped up the lagging of the system once it reached the desktop and intense cpu thing but booting problems still persisted.
    archive and install: some of the time it would fail to install in the middle of the installation, forcing me to start again, but once i completed it, issue still persisted.
    clean wipe of drive with restoration from time machine: computer speed better but still trouble when booting.
    Clean wipe of drive without migration of data: computer running and booting quickly, but occasionally still received circle slash instead of apple logo.
    At this point, i don't know where the source of the problem lies. The computer is old, but has never had an issue until recently. The problem is inconsistent, and all testing implies it doesn't exist, which makes its diagnosis extremely difficult. As it is a 2010 mac, it is clearly out of apple care and warranty so i cant go to a genius. I have a weak battery (80%) and my screen lid is a little loose from frequent use, but those are the only blatant problems i'm aware of with my mac.
    Any suggestions? I can gladly provide more info as needed.

    When you have the problem, note the exact time: hour, minute, second.  
    These instructions must be carried out as an administrator. If you have only one user account, you are the administrator.
    Launch the Console application in any of the following ways:
    ☞ Enter the first few letters of its name into a Spotlight search. Select it in the results (it should be at the top.)
    ☞ In the Finder, select Go ▹ Utilities from the menu bar, or press the key combination shift-command-U. The application is in the folder that opens.
    ☞ Open LaunchPad. Click Utilities, then Console in the icon grid.
    The title of the Console window should be All Messages. If it isn't, select
              SYSTEM LOG QUERIES ▹ All Messages
    from the log list on the left. If you don't see that list, select
              View ▹ Show Log List
    from the menu bar at the top of the screen.
    Each message in the log begins with the date and time when it was entered. Scroll back to the time you noted above.
    Select the messages entered from then until the end of the episode, or until they start to repeat, whichever comes first.
    Copy the messages to the Clipboard by pressing the key combination command-C. Paste into a reply to this message by pressing command-V.
    The log contains a vast amount of information, almost all of it useless for solving any particular problem. When posting a log extract, be selective. A few dozen lines are almost always more than enough.
    Please don't indiscriminately dump thousands of lines from the log into this discussion.
    Please don't post screenshots of log messages—post the text.
    Some private information, such as your name, may appear in the log. Anonymize before posting.

  • Anyone having trouble updating and loading apps after updating ipad software?

    I have an ipad(1st gen).  Updated to the latest software a few weeks ago.   Shows apps available for update, but wont download and load the app now.  Anyone else having this issue?  Also, safari frequently wont open a link and says safari is not connect to the network.  Have to close the browser and reopen it to get it working sometimes.  Frustrating!!! Help!!

    My iPad 1 won't update either- it says if I continue I will lose all information on the iPad.  I use it for my home business and can't lose all my data, contacts, and calendar items! HELP!
    It is crashing in the middle of app use, something is not right!

Maybe you are looking for

  • Render Error in fcp 6 on uprez clips

    Hello all, I'm getting this error message when trying to render a clip. Wondering if there was a shorter work around than the one I'm currently using? I'm trying to render a clip that has the file name for example: frankprores1920 or as simple as "Bo

  • Execution in Background

    hi...i want to use broadcasting for execute a query in background i know the configuraton but i want to know how the users can access the information of the executed query....how the information is stored?...users can navigate in the information or i

  • Making iMovies from unencrypted DVDs to post to YouTube

    My dad gave me a DVD of some live performances I have done and I want to post them on YouTube. I figured this would be easy with a Mac, but the process has proved to be extremely time consuming and so I am looking for a better way. First I followed t

  • I just changed computers: how do I now use creative cloud on my new computer?

    I just changed computers: how do I now use creative Cloud on my new computer?

  • Jar for classname:weblogic.jdbc.db2.DB2Driver

    Hi All: Does anybody knows what is the jar files that comes with weblogic 8.1 sp5 for the jdbc class name: weblogic.jdbc.db2.DB2Driver Yours, ThankFull