Can't get server to send file to client

On the client side, when I type in a filename in the JTextField and press enter, nothing happens. I want the server to get the file and send the contents back to the client. The client is connecting; I believe my problem is in my processConnection method in the server file.
Please advise. The code for both server.java and client.java is below.
import java.io.*;
import java.net.*;
public class Server
   private BufferedWriter output;
   private BufferedReader input;
   private ServerSocket server;
   private Socket connection;
   private String message;
   public void runServer ( )
      try
         server = new ServerSocket ( 8189 );
         connection = server.accept ( );
         getStreams ( );
         processConnection ( );
         closeConnection ( );         
      catch ( EOFException eofException )
         System.out.println ( "Client terminated connection" );
      catch ( IOException ioException )
         ioException.printStackTrace ( );
   private void getStreams ( ) throws IOException
      output = new BufferedWriter ( new OutputStreamWriter ( connection.getOutputStream ( ) ) );
      output.flush ( );
      input = new BufferedReader ( new InputStreamReader ( connection.getInputStream ( ) ) );
   private void processConnection ( ) throws IOException
      message = ( String ) input.readLine ( );    
      File file = new File ( message );
      BufferedReader fileInput = new BufferedReader ( new InputStreamReader
         ( new FileInputStream ( file ) ) );
      String str = fileInput.readLine ( );
      while ( str != null )
         output.write ( str );
         str = fileInput.readLine ( );
      output.flush ( );
      fileInput.close ( );    
   private void closeConnection ( ) throws IOException
      output.close ( );
      input.close ( );
      connection.close ( );
   public static void main ( String [ ] args )
      Server application = new Server ( );
      application.runServer ( );
import java.io.*;
import java.net.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Client extends JFrame
   private JTextField enterField;     
   private JTextArea displayArea;
   private BufferedWriter output;
   private BufferedReader input;  
   private Socket connection;
   private String message;
   public Client ( )
      super ( "Client" );
      Container container = getContentPane ( );              
      enterField = new JTextField ( 10 );
      enterField.addActionListener (
         new ActionListener ( )
            public void actionPerformed ( ActionEvent event )
               sendFile ( enterField.getText ( ) );
      container.add ( enterField, BorderLayout.NORTH );
      displayArea = new JTextArea ( );
      container.add ( displayArea, BorderLayout.CENTER );
      setSize ( 500, 400 );
      setVisible ( true );
   public void runClient ( )
      try
         connectToServer ( );
         getStreams ( );
         processConnection ( );
         closeConnection ( );
      catch ( EOFException eofException )
         System.out.println ( "Server terminated connection" );
      catch ( IOException ioException )
         ioException.printStackTrace ( );
   private void connectToServer ( ) throws IOException
      displayArea.setText ( "Attempting connection\n" );
      connection = new Socket ( InetAddress.getLocalHost ( ), 8189 );
      displayArea.append ( "Connected to: " + connection.getInetAddress ( ).getHostName ( ) );
   private void getStreams ( ) throws IOException
      output = new BufferedWriter ( new OutputStreamWriter ( connection.getOutputStream ( ) ) );
      output.flush ( );
      input = new BufferedReader ( new InputStreamReader ( connection.getInputStream ( ) ) );
      displayArea.append ( "\nGot I/O streams\n" );
   private void processConnection ( ) throws IOException
      message = ( String ) input.readLine ( );
      displayArea.append ( "\n" + message );     
   private void closeConnection ( ) throws IOException
      displayArea.append ( "\nClosing connection" );
      output.close ( );
      input.close ( );
      connection.close ( );
   private void sendFile ( String message )
      try
         output.write ( message );
         output.flush ( );
      catch ( IOException ioException )
         displayArea.append ( "\nError writing string" );
   public static void main ( String [ ] args )
      Client application = new Client ( );
      application.setDefaultCloseOperation ( JFrame.EXIT_ON_CLOSE );
      application.runClient ( );

How about some serialization:
URLConnection con = ....
con.setRequestProperty("Content-Type", "java/octet");
con.setDoOutput(true);
ObjectOutputStream oos = new ObjectOutputStream(con.getOutputStream());
oos.writeObject(dataSend);
stream = con.getInputStream();
ObjectInputStream ois = new ObjectInputStream(stream);
Object dataReceive = ois.readObject();
You determine the types of the objects that will carry the content,
they just need to be Serializable. Maybe you will wanr to change the connection type but I think it will be almost the same scheme
HTH
Mike

Similar Messages

  • I had renamed my user login name and assumed that there will be no change in the settings and files. When I login with the new profile name everything is gone. How can I get back all my files and settings?

    I had renamed my user login name and assumed that there will be no change in the settings and files. When I login with the new profile name everything is gone. How can I get back all my files and settings? Please help. Thanks.

    You should have asked this before you tried: Changing username or short name- User Account and Short Name- OS X- How to change user account name or home directory name.

  • How can I get a single jar file with NetBeans?

    How can I get a single jar file with NetBeans?
    When I create the project I get these files:
    dist/lib/libreria1.jar
    dist/lib/libreria2.jar
    dist/software.jar
    The libraries that have been imported to create the project are in separate folders:
    libreria1/libreria1.jar
    libreria2/libreria2.jar
    libreria1, libreria2, dist folders are all located inside the project folder.
    I added the following code to the build.xml:
    <target name="-post-jar">
    <jar jarfile="dist/software.jar">
    <zipfileset src="${dist.jar}" excludes="META-INF/*" />
    <zipfileset src="dist/lib/libreria1.jar" excludes="META-INF/*" />
    <zipfileset src="dist/lib/libreria2.jar" excludes="META-INF/*" />
    <manifest>
    <attribute name="Main-Class" value="pacco.classeprincipale"/>
    </manifest>
    </jar>
    </target>
    Of course there is also the project folder:
    src/pacco/classeprincipale.form
    src/pacco/classeprincipale.java
    Can you tell me what is wrong? The error message I get is as follows:
    C:...\build.xml:75: Problem creating jar: archive is not a ZIP archive BUILD FAILED (total time: 2 seconds)

    This is not a NetBeans forum, it is a JDeveloper forum. You might want to try http://forums.netbeans.org/. I also saw your other question - try looking in the New to Java forum: New To Java

  • How can we get  tag of XML file using SAX

    Hi ,
    I'm parsing one SAX parser , I'have almost done this parsing. i have faced problem for one case, i'e how can we get tag from XML file using SAX parser?
    XML file is
    <DFProperties>
    <AccessType>
    <Get/>
    </AccessType> <Description>
    gdhhd
    </Description>
    <DFFormat>
    <chr/>
    </DFFormat>
    <Scope>
    <Permanent/>
    </Scope>
    <DFTitle>gsgd</DFTitle>
    <DFType>
    <MIME>text/plain</MIME>
    </DFType>
    </DFProperties>
    I want out like GET and Permanent... means this one tag which is present inside of another tag.
    Handler class like
    public void startElement(String namespaceURI, String localName,
                   String qName, Attributes atts) throws SAXException {
    if(_ACCESSTYPE.equals(localName)){
                   accessTypeElement=ACCESSTYPE;
    public void characters(char[] ch, int start, int length)
                   throws SAXException {
    if (_ACCESSTYPE.equals(_accessTypeElement)) {
                   String strValue = new String(ch, start, length);
                   System.out.println("Accestype-----------------------------> " + strValue);
                   //System.out.println(" " + strValue);
    public void endElement(String namespaceURI, String localName, String qName)
                   throws SAXException {
    if (_ACCESSTYPE.equals(localName)) {
                   _accessTypeElement = "";
    . please any body help me

    Hi ,
    I have one problem,Please help me.
    1. How can I'll identify where exactly my Node is ended,means how how can we find corresponding nodename? in partcular place
    <Node> .............starttag1
    <NodeName>Test</NodeName>
    <Node>................starttag2
    <nodeName>test1</NodeName>
    </Node>..................endtag2
    <Node>.....................starttag3
    <NodeName><NodeName>
    <Node> .........................starttag4
    <NodeName>test4</NodeName>
    </Node>.......enddtag4
    </Node>...........end tag3
    </Node>............endtag1
    my code is below
    private final String _NODENAME = "NodeName";
    private final String _NODE = "Node";
    private String _nodeElement = "";
         private String _NodeNameElement = "";
    public void startElement(String namespaceURI, String localName,
                   String qName, Attributes atts) throws SAXException {
    if (_NODENAME.equals(localName)) {
                   NodeNameElement = NODENAME;
    if(_NODE.equals(localName)){
         System.out.println("start");
         if (_NODENAME.equals(localName)) {
                   NodeNameElement = NODENAME;
    public void characters(char[] ch, int start, int length)
                   throws SAXException {
    if (_NODENAME.equals(_NodeNameElement)) {
                   String strValue = new String(ch, start, length);
                   String sttt=strValue;
                   System.out.println("NODENAME: ************* " + strValue);
    if(_NODE.equals(_nodeElement)){
                   if (_NODENAME.equals(_NodeNameElement)) {
                        String strValue = new String(ch, start, length);
                        String sttt=strValue;
                        System.out.println("nodevalue********** " + strValue);
    public void endElement(String namespaceURI, String localName, String qName)
                   throws SAXException {
    if (_NODENAME.equals(localName)) {
                   _NodeNameElement = "";
    if(_NODE.equals(localName)){
                   System.out.println("NODENAME: %%%%%%%%%");
    please help me. How can I figure node ending for particular nodename

  • Where can I get help re: a file missing from Pages in iCloud?

    Where can I get help re: a file missing from Pages in iCloud?

    If the file was also on a mac, then there was a local copy of the file in ~/Library/Mobile Documents.  If you use Time Machine or any other backup program on your computer, then try restoring the file(s).  Similarly the same thing would be done on a PC, but I'm not sure where the icloud local copies are kept.

  • Where can I get codec for ISO files?

    Where can I get codec for ISO files?Premiere Elements

    An ISO is actually not a video file, it is a container... somewhat like a ZIP file that contains other files
    I do not know if it will PLAY what is inside an ISO, but I use Imgburn to write an ISO to DVD
    Read http://forums.adobe.com/thread/1322583 for notes on installing Imgburn WITHOUT any toolbar add-ons... Set Imgburn to use the slowest burn speed your drive and media will use... I set my burn speed to 1x and let Imgburn adjust to the actual minimum

  • How can I get rid of other files on my mac ?

    how can I get rid of other files on my mac ?

    Hope this helps.
    1. Empty Trash.
        http://support.apple.com/kb/PH10677
    2. Delete "Recovered Messages", if any.
        Hold the option key down and click "Go" menu in the Finder menu bar.
        Select "Library" from the dropdown.
        Library > Mail > V2 > Mailboxes
        Delete "Recovered Messages", if any.
        Empty Trash. Restart.
    3. Repair Disk
        Steps 1 through 7
        http://support.apple.com/kb/PH5836
    4. For more on this and very helpful tips:
        http://pondini.org/OSX/DiskSpace.html
        http://pondini.org/OSX/LionStorage.html
    5. Disk space / Time Machine ?/ Local Snapshots
       http://support.apple.com/kb/ht4878
    6 Re-index Macintosh HD
       System Preferences > Spotlight > Privacy
       http://support.apple.com/kb/ht2409

  • Can i get back the backup file what i deleted on icloud?

    Can i get back the backup file what i deleted on icloud?please, help me. thanks

    You can't. iSync has been discontinued since Mac OS 10.7 Lion. iSync has no connection with iCloud anyway.

  • How can I get GV and HDV files imported to Premier Elements 13. I know now that they are not supported. But does it exist ways to get them. I use camera HDR-HS7E?

    How can I get GV and HDV files imported to Premier Elements 13. I know now that they are not supported. But does it exist ways to get them. I use camera HDR-HS7E?

    skjeggi
    What is this HDR-HS7E - a miniDV camcorder that lets you do DV and HDV capture firewire?
    True, the DV and HDV capture firewire into the Premiere Elements 13 Capture window is gone. But, have you
    looked at the workaround suggested by PRE_help in this forum. The workaround is found in the following
    Adobe document....
    http://helpx.adobe.com/premiere-elements/kb/removed-features-formats-elements.html
    When your schedule permits, please let us know if that worked for you.
    Thank you.
    ATR

  • HT203106 Can I use AirDrop to send files from iPhone 5 to my iPad Air 2?

    Can I use AirDrop to send files from iPhone 5 to my iPad Air 2?

    Yes.
    Use AirDrop to wirelessly share content - Apple Support

  • A .pdf file is causing my notebook to freeze up. When I highlight it to delete, it will also freeze up the notebook. How else can I get rid of the file?

    A .pdf file is causing my notebook to freeze up. When I highlight it to delete, it will also freeze up the notebook. How else can I get rid of the file?

    Back up all data, then boot from your recovery partition (command-R at startup), launch Disk Utility, select your startup volume, and run Repair Disk (not Repair Permissions.) If any problems are found, repeat. Then reboot as usual.

  • Can Mac OS Server limit up time for clients

    Can Mac OS Server limit up time for clients like a linksys router can? I want to base the time limit on mac addresses.

    what exactly do you want to limit?
    uptime is the time since the computer has been turned on (total time running), sounds more like you would like to limit internet acccess...??

  • How can I get the directory.xml file for WL6.0?

    I have installed the ALBPM Enterprise WL6.01 and started it in my server.But I get the error message when I login.
    directory configuration runtime fails to initilize with
    resource:/Aqualogic/j2eewl/tomcate/webapps/../../webapps/webconsole/WEB-INF/directory.xml
    How can I get the XML file?

    aaa, ok i misunderstood your first post, i thought you are talking about unable to use the directory.xml from your application.
    Ok, well the directory.xml file that ALBPM uses is allways in /albpm6.0/j2eewl/conf/directory.xml if we are not talking about Standalone. And when you start your albpm server it picks up the directory.xml file from there. But it picks him up only when you start it...so if you made any changes to it, you have to restart the server.
    You should check the instalation folder of your ALBPM.
    If you want to change the user/pass in the directory.xml change it in that folder and restart ALBPM.
    If you don't know how to enter new password you have to use this sintax:
    <encrypt>newPassword</encrypt>
    Because if you open the xml file you have only <encrypted> tags, and you can't change those.
    I don't know what the xml file is doing in that tomcat folder though...maybe it get's copied to that location when you start the albpm WL
    Hope this helps
    Edited by Lex_ at 12/13/2007 10:27 PM

  • Can't get camera to send Pics to FTP on EX2

    I have a Avacom camera on my network. I am trying to get it to send pics to the EX2. The test says Device(WIFICAM) <script src="/t5/forums/postpage/board-id/test_ftp.cgi"></script> <script src="/t5/forums/postpage/board-id/get_status.cgi"></script> <script>// document.title = opener.str_device+'('+alias+')'; // </script>Test  ...  SucceedI have a share in the EX2 that has full read wite  User access to the share folder. I have enabled both FTP Access and WebDAV Service under Network Services and the share folder.I have rebooted and shut down. I have a Wire shark capture that shows the login and the picture file it's trying to upload to the EX2. I get a  "553 Users may not upload files" The EX2 seems to not set the share folder for the user. Is there a way to set what folder will be used by the login? Thanks for any help 220---------- Welcome to Pure-FTPd [privsep] [TLS] ---------- 220-You are user number 1 of 10 allowed. 220-Local time is now 23:11. Server port: 21. 220-IPv6 connections are also welcome on this server. 220 You will be disconnected after 10 minutes of inactivity. SYST 215 UNIX Type: L8 USER cambd 331 User cambd OK. Password required PASS mypassword 230 OK. Current restricted directory is / TYPE I 200 TYPE is now 8-bit binary PORT 192,168,1,231,136,249 200 PORT command successful STOR HSL-086176-CFZRY_0_20150727231121_5.jpg 553 Users may not upload files 553 Logout. 

    AdrianP15 wrote:
    I have a Avacom camera on my network. I am trying to get it to send pics to the EX2. The test says Device(WIFICAM) <script src="/t5/forums/postpage/board-id/test_ftp.cgi"></script> <script src="/t5/forums/postpage/board-id/get_status.cgi"></script> <script>// document.title = opener.str_device+'('+alias+')'; // </script>Test  ...  SucceedI have a share in the EX2 that has full read wite  User access to the share foulder. I have enabled both FTP Access and WebDAV Service under Network Services and the share foulder.I have rebooted and shut down. I have a Wire shark capture that shows the login and the picture file it's trying to upload to the EX2. I get a  "553 Users may not upload files" The EX2 seems to not set the share foulder for the user. Is there a way to set what foulder will be used by the login? Thanks for any help 220---------- Welcome to Pure-FTPd [privsep] [TLS] ---------- 220-You are user number 1 of 10 allowed. 220-Local time is now 23:11. Server port: 21. 220-IPv6 connections are also welcome on this server. 220 You will be disconnected after 10 minutes of inactivity. SYST 215 UNIX Type: L8 USER cambd 331 User cambd OK. Password required PASS mypassword 230 OK. Current restricted directory is / TYPE I 200 TYPE is now 8-bit binary PORT 192,168,1,231,136,249 200 PORT command successful STOR HSL-086176-CFZRY_0_20150727231121_5.jpg 553 Users may not upload files 553 Logout. Go to NAS webpage --> Share tab and enable FTP access for folder you would like to give FTP access to.  I believed you only turn on the FTP from the setting but have not enable with share folder to allow FTP access to.

  • Can't get mail to send

    I can't get two of my mail programs to send mail. They send from the ipad with the same settings as the mail program. Is there something different between the ipad and the air mail programs that would make it different?
    Thanks

    One thing you can do is find out from Sky Broadband if the SMTP server requires authentication or not and what port the SMTP server uses.

Maybe you are looking for

  • USB to Svideo

    I'm new to MAC so please be patient. Does anyone know if I can connect my MacBook Pro to my TV using my USB to svideo converter box (works on my old PC) or do I have to purchase a mini displayport adapter?

  • Java Heap space problem

    Hi, I have an web application which throws out of memory error when more than 5 users logs in .I am using jboss server with linux box.I have 1Gb physical memory. I tried changing the jvm options but still it's not working .I am using lots of session

  • Storagetek 2540 - OVM 3.1.1

    Hi experts, I'm tring to configure OVM 3.1.1with a Storagetek 2540/2540-M2 array, is this supported? Do I have to install RDAC drivers in Oracle VM server? I have this platform: OVM Manager 3.1.1 on Sunfire X2270-M2 up and running OVM Server 3.1.1 on

  • CE 7.11 caf~runtime~ear error

    Hi, I'm currently developing CAF application in CE 7.11 SP3 with NWDI. I had encountered an error activating CAF application. From the default trace, it hints that the CAF application cant be started due to the missing of cafcoreear and cafruntimeear

  • Repair Store [North Houston]

    Hi, are there are any repair stores in North Houston for iPods? I've looked at Dr.CellPhone, but I'm not sure how reliable the reviews are. I've also been told about looking at iResQ.com. Are there are any other sites or local businesses that I shoul