Socket Question: Client not receiving the server messages...

I have a client and server where in the client sends the server a file name to look for. The server looks for that file and checks for its existence and reads the file line by line displays it and then sends it to client. The client should recieve the contents send by the server and display it line by line. Here is what I have done
Server
import java.io.*;
import java.net.*;
import java.awt.*;
import javax.swing.*;
public class Server extends JFrame
     public static void main( String args[] )
//Pass the port no as an argument
Server s = new Server(Integer.parseInt(args[0]));
s.runServer();
     private ServerSocket ss;
     private Socket Connection;
     private BufferedReader input;
     private BufferedWriter output;
     private PrintWriter poutput;
     private int port;
     private int bufLength;
     private JTextArea display;
     public Server(int port)
          super( "Socket Server" );
          display = new JTextArea();
          getContentPane().add( display, BorderLayout.CENTER );
          setSize( 400, 300 );
          setVisible( true );
// Construct of a socket
          try
               ss = new ServerSocket(port);
          catch( SocketException se )
               se.printStackTrace();
               System.exit( 1 );
          catch( IOException io )
               io.printStackTrace();
     public void runServer()
          String fileName = null;
          try
               Connection = ss.accept();
               input = new BufferedReader(new InputStreamReader(Connection.getInputStream()));
               OutputStreamWriter out = new OutputStreamWriter(Connection.getOutputStream());
               boolean done = false;
               while(!done)
                    String lline = input.readLine();
                    if (lline != null)
                         done = true;
                         display.append( "\nThe server has read the file name:" + lline);
                         fileName = lline.trim();
               input.close();
               File fileLoc = new File(fileName);
               if (fileLoc.exists())
                    input = new BufferedReader(new FileReader(fileLoc));
                    boolean eof = false;
                    while (!eof)
                         String line = input.readLine();
                         if (line == null)
                              eof = true;
                         else
                              display.append( "\nThe server has read the line:" + line);
                              out.write(line);
                         Connection.close();
               else
                    String message = "The file specified does not exist on this server. Recheck your request";
                    poutput.println(message);
               out.flush();
          catch (Exception e)
               System.out.println(e);
Client
import java.io.*;
import java.net.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Client extends JFrame implements ActionListener
private JTextField enter;
private JTextArea display;
private BufferedReader bufferInput;
private BufferedWriter bufferOutput;
private Socket connection;
private JPanel p;
private JLabel label;
private PrintWriter out;
private int serverPort;
private int bufLength;
public Client(int serverPort)
super( "Client Socket" );
label = new JLabel("Enter file name to retrieve:");
enter = new JTextField();
enter.addActionListener( this );
getContentPane().add( enter, BorderLayout.NORTH );
display = new JTextArea();
getContentPane().add( display, BorderLayout.CENTER );
setSize( 400, 300 );
setVisible( true );
     String serverHost = "spentapa-nt";
try
connection = new Socket(serverHost, serverPort);
//Input stream
bufferInput = new BufferedReader(new InputStreamReader(connection.getInputStream()));
//Output Stream
     out = new PrintWriter(connection.getOutputStream(),true);
catch( SocketException se )
se.getMessage();
se.printStackTrace();
System.exit( 1 );
catch( IOException io )
          io.printStackTrace();
public void actionPerformed( ActionEvent e )
     String fileName = null;
try
          Object o = e.getSource();
          if(o==enter)
               fileName = enter.getText();
               System.out.println("The file entered is :"+ fileName);
          out.println(fileName);
display.append( "\nThe File is:" + "\n" );
//sends the text file to the server
//receives the contents of the text file from the server
boolean eof = false;
boolean eof = false;
     while (eof)
          String line = bufferInput.readLine();
          if (line == null)
               eof = true;
          else
               display.append( "\n" + line);
          System.out.println(line);
     out.flush();
catch ( Exception ioe )
display.append(ioe.getMessage() + "\n" );
ioe.printStackTrace();
public static void main( String args[] )
//Pass the Host Name and Port no. as arguments
Client c = new Client(Integer.parseInt(args[0]));

For starters, change while(eof) to while(!eof)

Similar Messages

  • How do you get your security questions reset? The email that I set up is not receiving the reset message.

    I'm trying download music/apps from iTunes. I'm being asked to sign into my Apple ID to answer my security questions. Which I forgot. It allows you to send an email if you forgot you questions. That email, which belongs to my wife, has not received any info from Apple to fix the problem. What should I do to fix this annoyance?

    You need to ask Apple to reset your security questions; ways of contacting them include clicking here and picking a method for your country, phoning AppleCare and asking for the Account Security team, and filling out and submitting this form.
    (97045)

  • Not receiving the 486 message from CUCM to Genesys via SIP trunk.

    I have setup where Genesys is used along with CUCM 9.1
    Below is the snapshot how it will look for call flow.
    PRI----V.G----CUCM---SIP trunk (created in CUCM)-----Geneys server.
    Query here is for outbound call from SIP softphone to PSTN, where if the PSTN user cancel the call.
    the SIP phone is still assuming the call is continuing and after 40 sec its getting disconnected.
    after looking in to the sip traces... it looks like that SIP trunk from cucm is not sending the user busy message 486....
    (checked in V.G and its giving user busy)...but in the CUCM its not getting sent to the genesys...
    After some time in genesys server itself send the 480 Temporarily Not Available message...
    I assume I  should get the 486 message from CUCM to genesys when the PSTN party disconnect the call without answering.
    Please assist.

    From logs what i can see is after one min call legs stops transmitting and receiving packets.
    You certainly need to check this Genesys support for this behavior , as far as I know  there is no problem either with the CUCM or with VG.
    1477 : 1515 22820290ms.1 +0 pid:0 Originate  connecting
    dur 00:01:15 tx:3765/602400 rx:3387/541760
    IP 10.129.0.45:32596 SRTP: off rtt:0ms pl:67720/140ms lost:0/1/0 delay:55/55/65ms g711ulaw TextRelay: off
    1477 : 1514 22820290ms.2 +0 pid:0 Originate  active
    dur 00:01:16 tx:3387/568856 rx:3838/614080
    Tele 0/3/0:15 (1514) [0/3/0.31] tx:76760/76760/0ms g711ulaw noise:-68 acom:3  i/0:-64/-62 dBm
    1477 : 1515 22820290ms.1 +0 pid:0 Originate  connecting
    dur 00:01:26 tx:4330/692800 rx:3387/541760
    IP 10.129.0.45:32596 SRTP: off rtt:0ms pl:67720/140ms lost:0/1/0 delay:55/55/65ms g711ulaw TextRelay: off
    1477 : 1514 22820290ms.2 +0 pid:0 Originate  active
    dur 00:01:30 tx:3387/568856 rx:4515/722400
    Tele 0/3/0:15 (1514) [0/3/0.31] tx:90290/90290/0ms g711ulaw noise:-68 acom:3  i/0:-67/-61 dBm
    Rate all the helpful post.
    Thanks
    Manish

  • Client not receiving the software update FROM SCCM 2012 R2

    We have SCCM 2012 R2 installed and configured for SUP.and i have synchonice the SUP with WSUS server in the same which is there in the same machine.
    Now i can able to deploy the software update from SCCM 2012 R2 without any erro to the windows 7clients, but client side when i check there is no update installed in the clients , but seems there is no error in the client logs

    Hi,
    I'd start with running a "Software Updates Scan Cycle" from the configuration manager control panel applet and check the log file Windowsupdate.log, WUAhandler.log.
    We
    are trying to better understand customer views on social support experience, so your participation in this
    interview project would be greatly appreciated if you have time.
    Thanks for helping make community forums a great place.

  • I didn't  receive the verification message for my apple ID

    I can't verify my apple ID because i did not receive the verification message on my email.

    Contact iTunes support: http://www.apple.com/support/itunes/contact/

  • I receive the following message under Boot Camp Assistant: "Can't install the software because it is not currently available from the Software Update server.

    I am trying to install the software drivers for Windows 7 Home using Boot Camp 4 Assistant. I receive the following message: "Can't install software because it is not currently available from the Software Update server." Why is this happening?

    You keep it on the usb stick for after you boot into Windows. From Windows you install the Windows Support software on the stick. Do you realize that you need to buy and install Windows? The Windows Support software you downloaded is only the Windows drivers for your hardware.
    Read the Boot Camp installation instructions and help guides located here: http://www.apple.com/support/bootcamp/

  • Hello ..Forgot your answer to the secret question and did not receive an email message

    Hello ..Forgot your answer to the secret question and did not receive an email message

    As we don't know your location, call Apple from your National help number per the link below and ask them for help from the security people.   Contact Apple support
    It would also help if you could find a moment to fill in your profile so that we are better equipped to answer your questions.

  • Why has not received the message about the change secret Questions?

    Why has not received the message about the change secret Questions on my email?

    Be patient. You don't get an immediately notification email. Record the Claim Number somewhere in case something goes wrong. It can take up to 72 hours. I got mine in about 54 hours.

  • My Macbook pro Early 2008 is randomly slow at starting up and when I am backing up to my time capsule I am receiving the following message 'Time machine could not complete the backup. '' ''The backup disk image ''/Volumes/name time capsule/ my name MacBoo

    My Macbook pro Early 2008 is randomly slow at starting up and when I am backing up to my time capsule I am receiving the following message 'Time machine could not complete the backup. '' ''The backup disk image ''/Volumes/name time capsule/ my name MacBook Pro (4).sparsebundle'' could not be accessed (error-1).
    Problem started after deleting parrell desktop and window7 ?
    Please help?

    Look at the more like this column on the right.. this is the most frequently asked question in this discussion area.
    Reboot the TC.. restart the whole network if the simple reboot did not work.. start in order. modem.. router/TC.. clients. 2min gap.
    Read C12 here. http://pondini.org/TM/Troubleshooting.html

  • I can no longer log into my ichat linked to my gmail.  right after opening up ichat, receive the following message:  lost connection with jabber.  the server has unexpectedly disconnected.

    i can no longer log into my ichat linked to my gmail.  right after opening up ichat, receive the following message:  lost connection with jabber.  the server has unexpectedly disconnected.  how to troubleshoot?  thanks.

    Hi,
    There can be many reasons why the Login is "up the creek".
    Any break in the network at your end whilst logged in will cause  an issue.
    A sort of discrepancy between what iChat thinks the state should be and what the server thinks.
    If they don't agree the server will refuse to accept.
    A Crash at the server end which does not log you out properly will also do it.
    Any file at any time can be come corrupted.
    Luckily with the iChat .plists they are recreated if removed with an iChat Restart.
    If it were AIM you can also get your Account Suspended  and this will not log you in.
    (It tends to happen from Chat rooms where people notify AIM about bad behaviour (as they see it) and you have to apply to get Un-suspended).
    Most of the big IM services use multiple servers.
    Sometimes these go out of Sync.
    In the case of AIM this happens when they remove Old unused Screen Names from people's Buddy List prior to making them available for re-registration.  I am not sure if this happens at Google.
    You seem to be talking about an account that has worked at Work and having new computer at home.
    As I mentioned the Priority thing you have not said that it has coincided with the new computer logging in  (this will kick the work Computer out of Google whether you are logged in  on the Web Mail page or in iChat)
    IN addition to that iChat stays partially logged in for Off Line IMs
    This is done in the background by a support app called iChatAgent
    If your Computer is ON but ichat is not started people can still send you Messages.
    Instead of saving these on the server until you login iChat will start up.
    Depending if the home Mac is effecting the Work Login it may be holding sway over your Login.
    Using your girlfriend's login may have booted her Off Line where she normally uses the name/login.
    The AIM Side can be specifically set to allow Multiple Logins and therefore NOT allow them.  If this happens you get a warning and messages to do something about it.
    You do not get these in any Jabber or Google Login as the Priority setting is supposed to take care of it.
    If the Login works at the Web Mail Login and on one computer then the .plist on the work computer is the most likely issue.
    There is a small chance that a Corrupt Buddy Pic (Home Folder/Library/Caches/com.apple.iChat/Pictures) may be the cause.
    Set this folder to icon view and also use the Finder's View Menu > Show View Options and select icon view.
    This should show all pics as their icon.
    Check that all display properly.
    At this point I would try a COMBO version update install of the last Update you did over what you have.
    This often corrects hard to trace things
    The 10.5.8 COMBO is here
    11:28 PM      Monday; June 20, 2011
    Please, if posting Logs, do not post any Log info after the line "Binary Images for iChat"
     G4/1GhzDual MDD (Leopard 10.5.8)
     MacBookPro 2Gb( 10.6.7)
     Mac OS X (10.6.7),
    "Limit the Logs to the Bits above Binary Images."  No, Seriously

  • When I try to import, I receive the following message: "An internal error has occurred: not enough memory".  I always download my photos onto an external hard drive.

    Yesterday,I downloaded an update for Lightroom 5.  Now when I try to import, I receive the following message: "An internal error has occurred: not enough memory".  The message comes up right after I click import, before I choose a file to upload.Here is the information I can think of that might be needed to answer this question:
    - I always download my photos onto an external hard drive.It is about 10 % full.
    - It says I have Lightroom 5.6  64 bit
    - I am working from a newer laptop (Windows).  The internal drive on the laptop has 289 gb and I am using 61 gb total memory.
    - I have edited 2794 photos in Lightroom and it is all in one catalog.
    - I did not have this problem until I made the update.  I did have my first "bug" earlier this week when one of my photos had a line show up through the middle of it when I exported it. I was able to export it a second time without the line.
    If there is more info. needed, let me know.  I do photography as a hobby and know enough about Lightroom to edit out blemishes and adjust color balance, but not too much more, so forgive my ignorance if this is an obvious fix.
    Sincerely,
    Adrianne

    Not Enough Memory typically refers to RAM.  How much RAM do you have on your 64-bit OS computer?  Do you have other programs running that may be using most of the memory?

  • My Revolution Not Receiving The Whole Text Message

    Hello, lately I have been having a problem receiving the whole text message. People with smart phones text sometimes page length texts. I have no problem sending out page length text, but when someone sends me one, from many different companies and phone types, I only receive what the phone recognizes as the first part of the text message.
    An Example is:
    "Hello, I was wondering what you are doing later. I was thinking we could go to the shopping later at the mall. Do you ha"
    I primary text people so when I do not receive the whole text it is very frustrating.

    It's lies that you haven't received any other complaints on this issue.  1) because I have called repeatedly on this exact issue among many others with this phone and 2) here are some of about a dozen posts on this:
    https://community.verizonwireless.com/message/876695#876695
    and another:
    https://community.verizonwireless.com/message/875860#875860
    and another:
    https://community.verizonwireless.com/message/875820#875820
    granted some are recent, but if you search your forums you will see plenty.
    You used to and still state that you never hear of any of the many issues with this phone, including when it would randomly reboot.  Same phrase, "we have yet to hear of other cases with this device."  Bull...
    I too will be heavily considering leaving Verizon after over 10 years of being a customer not due to an LG phone sucking this bad, but your company's repeated refusal to acknowledge our concerns and treat us like we are ******. 
    Like your master reset phrase above.  So you think that computing devices need a fresh start anytime something goes wrong is just not correct.  If that were the case every time I have fragments between nodes in a clustered server environment I'm supposed to factory reset them?!  NO, you debug it and get it working correctly!  This issue is fragmenting withing your sms/mms delivery system, so fix it!  As a sysadmin for a scientific super computing institute I guarantee I know more about computing devices than you ever will, and I can say your workarounds are asinine and only prolong your customer's issues with a clearly defective device. 
    As with this, although not your manufactured device, it is something you sell and therefore you debug these issues across your network or give those of us that can the ability to do so, but alas another locked boot loader and if we were to root the device to mitigate these issues then we screw our self by trying to help our self.  It's always our fault, as we must have done something wrong.

  • Why is it that I can't receive the email to reset my security questions and answers.. My email information is all accurate but I'm not receiving the email and I've even checked spam and junk folders.. Can someone please help me please???

    Why is it that I can't receive the email to reset my security questions and answers.. My email information is all accurate but I'm not receiving the email and I've even checked spam and junk folders.. Can someone please help me

    Are you able to receive any mail at all? If not, make sure that all of your information for mail is accurate in settings again. if you still have nothing, go to your email through safari. (example: www.yahoo.com) If you do not see the emails here either, it is a problem with the password reset server not your mail app.

  • I can reset my security questions.  I have checked my email and but am not receiving the email to reset.  Its not in spam.

    How can I reset my security questions for icloud account.  I am not receiving the reset email.   Is there a way to change where the email is being sent?   ice checked my spam folders.

    The easiest thing to do is to contact Apple for assistance by going to https://expresslane.apple.com, then click More Products and Services>Apple ID>Other Apple ID Topics>Forgotten Apple ID security questions.
    This explains how to change your rescue address: Manage your Apple ID primary, rescue, alternate, and notification email addresses.

  • When trying to connect to itunes i receive the following message, "iTunes could not connect to the iTunes store"  An unknown error occured (-3212)

    Help me, when trying to connect to iTunes or the iTunes Store I receive the following message. "iTunes could not connect to the iTunes Store." An unknown error occurred (-3212).

    iTunes has been denied by your firewall. Add iTunes to your firewall allowed list.

Maybe you are looking for