Socket problem with reading/writing - server app does not respond.

Hello everyone,
I'm having a strange problem with my application. In short: the goal of the program is to communicate between client and server (which includes exchange of messages and a binary file). The problem is, when I'm beginning to write to a stream on client side, server acts, like it's not listening. I'd appreciate your help and advice. Here I'm including the source:
The server:
import java.io.IOException;
import java.net.ServerSocket;
public class Server
    public static void main(String[] args)
        ServerSocket serwer;
        try
            serwer = new ServerSocket(4443);
            System.out.println("Server is running.");
            while(true)
                ClientThread klient = new ClientThread(serwer.accept());
                System.out.println("Received client request.");
                Thread t = new Thread(klient);
                t.start();
        catch(IOException e)
            System.out.print("An I/O exception occured: ");
            e.printStackTrace();
}ClientThread:
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.ByteArrayOutputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.net.Socket;
import java.net.SocketException;
public class ClientThread implements Runnable
    private Socket socket;
    private BufferedInputStream streamIn;
    private BufferedOutputStream streamOut;
    private StringBuffer filePath;
    ClientThread(Socket socket)
            this.socket = socket;     
    public void run()
        try
             this.streamIn = new BufferedInputStream(socket.getInputStream());
             this.streamOut = new BufferedOutputStream(socket.getOutputStream());
            int input;
            filePath = new StringBuffer();
            System.out.println("I'm reading...");
            while((input = streamIn.read()) != -1)
                 System.out.println((char)input);
                 filePath.append((char)input);
            this.streamOut.write("Given timestamp".toString().getBytes());
            ByteArrayOutputStream bufferingArray = new ByteArrayOutputStream();
              while((input = streamIn.read()) != -1)
                   bufferingArray.write(input);
              bufferingArray.close();
            OutputStream outputFileStream1 = new FileOutputStream("file_copy2.wav");
              outputFileStream1.write(bufferingArray.toByteArray(), 0, bufferingArray.toByteArray().length);
              outputFileStream1.close();
            this.CloseStream();
        catch (SocketException e)
            System.out.println("Client is disconnected.");
        catch (IOException e)
            System.out.print("An I/O exception occured:");
            e.printStackTrace();
    public void CloseStream()
        try
            this.streamOut.close();
            this.streamIn.close();
            this.socket.close();
        catch (IOException e)
            System.out.print("An I/O exception occured:");
            e.printStackTrace();
}The client:
import java.io.*;
public class Client
     public static void main(String[] args) throws IOException
          int size;
          int input;
          //File, that I'm going to send
          StringBuffer filePath = new StringBuffer("C:\\WINDOWS\\Media\\chord.wav");
          StringBuffer fileName;
          InputStream fileStream = new FileInputStream(filePath.toString());
        Connect connection = new Connect("127.0.0.1", 4443);
        String response = new String();
        System.out.println("Client is running.");
          size = fileStream.available();
          System.out.println("Size of the file: " + size);
        fileName = new StringBuffer(filePath.substring(filePath.lastIndexOf("\\") + 1));
        System.out.println("Name of the file: " + fileName);
        connection.SendMessage(fileName.toString());
        response = connection.ReceiveMessage();
        System.out.println("Server responded -> " + response);
        ByteArrayOutputStream bufferingArray = new ByteArrayOutputStream();
          while((input = fileStream.read()) != -1)
               bufferingArray.write(input);
          bufferingArray.close();
        FileOutputStream outputFileStream1 = new FileOutputStream("file_copy1.wav");
          outputFileStream1.write(bufferingArray.toByteArray(), 0, bufferingArray.toByteArray().length);
          outputFileStream1.close();
          byte[] array = bufferingArray.toByteArray();
          for (int i = 0; i < array.length; ++i)
               connection.streamOut.write(array);
          response = connection.ReceiveMessage();
System.out.println("Server responded -> " + response);
connection.CloseStream();
Connect class:import java.io.*;
import java.net.Socket;
import java.net.UnknownHostException;
public class Connect
public Socket socket;
public BufferedInputStream streamIn;
public BufferedOutputStream streamOut;
Connect(String host, Integer port)
try
this.socket = new Socket(host, port);
this.streamIn = new BufferedInputStream(this.socket.getInputStream());
this.streamOut = new BufferedOutputStream(this.socket.getOutputStream());
catch (UnknownHostException e)
System.err.print("The Host you have specified is not valid.");
e.getStackTrace();
System.exit(1);
catch (IOException e)
System.err.print("An I/O exception occured.");
e.getStackTrace();
System.exit(1);
public void SendMessage(String text) throws IOException
this.streamOut.write(text.getBytes());
System.out.println("Message send.");
public void SendBytes(byte[] array) throws IOException
     this.streamOut.write(array, 0, array.length);
public String ReceiveMessage() throws IOException
     StringBuffer elo = new StringBuffer();
     int input;
     while((input = streamIn.read()) != -1)
          elo.append((char)input);
     return elo.toString();
public void CloseStream()
try
this.streamOut.close();
this.streamIn.close();
this.socket.close();
catch (IOException e)
System.err.print("An I/O exception occured: ");
e.printStackTrace();

The problem that was solved here was a different problem actually, concerning different source code, in which the solution I offered above doesn't arise. The solution I offered here applied to the source code you posted here.

Similar Messages

  • I have a problem with my ipod touch it does not light at all, what should I do?

    I have a problem with my ipod touch it does not light at all, what should I do?

    Try the troubleshooting here for your specific symptom:
    iPod touch: Hardware troubleshooting

  • The start/stop bar on my i Tunes app does not respond properly. Please advise.

    The start/sop bar on my i Tunes app does not respond properly. Please help.

    It can be that the library path, or files, are corrupted. What happens if you set a different path to save the library?

  • Server App does not change SMB AFP option as expected

    I have been fighting SMB shares on Mac OS since upgrading to Mountain Lion (I skipped Lion) and I think I have the situation figure out at least in my case.
    First Opportunistic Locking needs to be turned off in Windows 7. It does not appear that Mac OS supports it and this is why my connection got disconnected.
    In the regestry at, [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\LanmanWorkstation\Paramet e rs] add this,  "OpLocksDisabled"=dword:00000001
    Now for the SMB shares for people using the Server App. The Server App. is where you setup shares but I think there is a bug. In my case the Server App. was not actually turning on SMB and/or AFP services for the users listed in the server permissions. I had to go to Sharing under System Preferences then select the share I want the service to apply to then select Options. I found that the SMB and AFP services were not enabled even though they had been set in the Server App. Once I enabled them all was as it should be.

    Same problem. I had to rebuild my LDAP database and when I imported the users and groups, they appear in Workgroup Manager but they don't appear in Server app. Well..   they do sometimes.  If I click the "Add Users" button, sometimes they'll appear briefly then go away in Server app. I can also edit a user and look at their group membership via Server app and the groups from Workgroup Manager appear but they are grayed out...  also, the users from the LDAP server will disappear at first and I have to click on another button, like "Configure Network" and then click back on "Add Users" and the network users will be there...  but no group.
    This is crazy.  It's like working on a '74 Chevy Vega.  Did ANYONE at Apple QA this?

  • Server.app does not authenticate network admin users

    Running fresh installation of Lion Server 10.7.3. I'm logged in as the original, local, administrator.
    I open Server.app and successfully log in to the local machine with the local administrator creditials. I create a networked user allowed to administer the machine. Close Server.app window.
    Attempt to log in as the new networked administrator. I get a message about using the server's self-signed certificate. I click accept, then the log-in shakes it head, won't let network admin log-in. Repeated attempts to log in do not show the certificate warning -- the log-in fails every time, though.
    Attempt to log is as local admin, works OK.
    How to fix?

    Hi Stefan, I have the Server app problem here on my Xserve 2009 and it happened after about 14 days of working correctly. No users or groups(850 network) show in the panes other than the two local admin users on the server. The +/- buttons are greyed out also. If you enter some letters for a search in Users/Groups it will actually display the network users containing the letters and eventually it populates the window with network users up to the usual 500+ limit but refresh and they all disappear again. Thinking back before it happened I used WGM to add a new user instead of Server and it was shortly after when the users "disappeared" and the+- buttons greyed out. I dont have much confidence in Server app at the moment and im just glad WGM/SA is still in operation. I agree with Danny_Sch that Server app starts to act strangely after using WGM
           WGM acts as usual with all my 850 users showing from the OD and Server admin shows all my services running ok. All users can log in and out fortunately at the moment. This happened initially when I migrated to Lion and I had to use my OD archive demoting and promoting to master to get it to work but I dont want to have to rebuild the whole thing again as we have very limited downtime to do it in a big institution etc. I'm trawling the net looking for a fix but no definitive answer. Has anyone reported this as a bug to Apple I wonder?

  • Problems with LDAP: "LDAP server prefix is not of the correct format"

    Hello!
    We use a Mac OS X Server (10.4.9) with Open Directory for authentication of the clients in our network. Furthermore, that machine serves home directories and mobile accounts.
    Every now and then a client hangs during login: After submitting login information, the system does not respond anymore (shows 'hourglass'). A few minutes later, the login process continues.
    The system log on the client contains the following lines:
    Apr 12 08:31:16 hostname kernel[0]: System Sleep
    Apr 12 08:31:16 hostname kernel[0]: Enabling XMM register save/restore and SSE/SSE2 opcodes
    Apr 12 08:31:16 hostname kernel[0]: Started CPU 01
    Apr 12 08:31:16 hostname kernel[0]: IOBluetoothHCIController::restartShutdownWL this is a wake from sleep
    Apr 12 08:31:16 hostname kernel[0]: System Wake
    Apr 12 08:31:17 hostname kernel[0]: AppleYukon - en0 link active, 100-Mbit, full duplex, symmetric flow control enabled
    Apr 12 08:31:18 hostname DirectoryService[53]: Search connection failure: During an attempt to bind to [X.Y.235.104] LDAP server.
    Apr 12 08:31:18 hostname DirectoryService[53]: Search connection failure: Disabled future attempts to bind to [X.Y.235.104] LDAP server for next 120 seconds.
    Apr 12 08:31:24 hostname kernel[0]: AFPSleepWakeHandler: waking up
    Apr 12 08:31:43 hostname DirectoryService[53]: DSLDAPv3PlugIn: DHCP option 95 error since obtained [X.Y.235.32] LDAP server prefix is not of the correct format.
    Apr 12 08:31:44 hostname /System/Library/CoreServices/MirrorAgent.app/Contents/MacOS/MirrorAgent: LWNotifyWithData: CFMessagePortSendRequest returned error -2.
    Apr 12 08:35:33 hostname DirectoryService[53]: Search connection failure: During an attempt to bind to [X.Y.235.104] LDAP server.
    Apr 12 08:35:33 hostname DirectoryService[53]: Search connection failure: Disabled future attempts to bind to [X.Y.235.104] LDAP server for next 120 seconds.
    Apr 12 08:36:04 hostname kernel[0]: AFP_VFS afpfs_mount: /Volumes/Users, pid 256
    What is the cause for that failure?
    Regards, Martin Burger
    iMac 20" (2 GHz Intel Core Duo) Mac OS X (10.4.9) Server: Dual 2.5 GHz PowerPC G5 with Mac OS X Server (10.4.9)

    Don't do DHCP based binding, configure it manually.
    -Ralph

  • Tungsten E2: On with a blank screen. Does not respond to resetting or to On/Off button.

    Three times in the past couple of months my Tungsten E2 has appeared with a lit, completely blank screen. It does not respond to the On/Off button nor to resetting, either soft or hard. This is true whether nor it is connected to its charger.
    By accident I discovered that I can recover by letting power run down. Eventually it shuts down. I then connect it to its charger; it recharges and recovers. All I lose, so far as I know, is the date and time.
    I'd appreciate any suggestions for preventing this from happening in the future or for an easier and quicker way to recover.
    Thanks,
    - Alan
    ps. I realize that there are several similar messages on these boards, but I didn't find any suggestions that worked for me.
    Post relates to: Tungsten E2

    Are you sync'ing the new device to the same username in Palm Desktop as an older device?
    If you are, this will cause problems on the new device. When you sync the device, it saves the device settings, 3rd party apps, preferences, etc. in the backup folder in the username folder on the PC. When you sync the new device it copies the contents of the backup folder for the old device to the new device. This will cause corruption in the settings for the new device thus causing erratic behavior of the new device.
    If you are, you may need to hard reset your device and rename your backup folder. Go to http://www.palm.com/cgi-bin/cso_kbURL.cgi?ID=887 and follow the directions to do a hard reset. Next before you hotsync your data back over you will need to rename your backup folder, to do that go here;
    XP
    C:\program files\palm or palm one\[hotsync username]\ and rename your backup
    folder to backup.old
    Vista
    Start-->documents\Palm OS Desktop\[hotsync username]\ and rename your backup
    folder to backup.old
    Then hotsync to your current hotsync name and all your contacts, calendar,
    tasks, and memos will come back over.
    Show file extensions for XP or Vista
    XP
    If you can not view file extensions on your PC I would like you to open a
    folder go to Tools-->Folder Options--> View (tab) and under show hidden
    files and folders uncheck hide file extensions for known file types.
    Vista
    Open control Panel go to Folder Options--> View (tab) and under show hidden
    files and folders uncheck hide file extensions for known file types.
    Post relates to: Palm i705

  • HT4764 when i open safari, it opens with a highlighted screen and does not respond

    when i open safari, it opens with a highlighted screen and does not respond

    So it seems the issue is when iMovie is wanting to creat thumbnails, if I ask it to ignore then it's fine but if not it hangs up searching for the video file.

  • What to do if the contact of a APP does not respond (APP=Fish Society)

    What to do if the contact of a APP does not respons. IT about APP=Fish Society of Global Agent Inc

    If the developer doesn't respond, there's really not much you can do. If you did not receive an in-app purchase, were overcharged for such a purchase, or the game just won't work, you can try contacting iTunes Store support:
    http://www.apple.com/support/itunes/contact/
    but they may just direct you back to the developer.
    Regards.

  • A problem with Reader's Digest App

    Hi there.
    I just a bought a iPad yesterday. I downloaded the Reader's Digest app and subscribed for a 1-year subscription. But now when I download the magazine it gets stuck at 60.1MB/228MB and gives an error "Cannot to connect to the server at this time"
    I have been trying to download it since morning.
    Does anyone know the solution to this?
    Thanx

    Trying to download the September issue of my Reader's Digest subscription.  The app says I need to download the latest app.  I do so.  I go back to Newsstand to download my September issue.  The apps says I need to download the lastest app.  I go into iTunes and click UPDATE.  I sync my iPad.
    I go back to Newsstand to download my September issue.  The apps says I need to download the lastest app.  I go into iTunes and click UPDATE.  I sync my iPad.
    I go back to Newsstand to download my September issue.  The apps says I need to download the lastest app.  I go into iTunes and click UPDATE.  I sync my iPad.
    I go back to Newsstand to download my September issue.  The apps says I need to download the lastest app.  I go into iTunes and click UPDATE.  I sync my iPad.
    Anyone see a pattern here?  Comments in the app in iTunes store shows others are having a problem as well.  So, uh, fix it?  Duh?

  • Defining Virtual Hosts so the Server App does not hijack them?

    Does anyone know how one might define manually define virtualhosts in Lion Server so the OS does not go and trash them, or mess with the conf files? Right now the server keeps stealing any virtual hosts I create manually and creating conf files to the standard of the Server App. The problem is I have several virtual hosts that have custom information in them and I need to restore the file whenever this happens. Any ideas?

    Put all your config files in something unknown to Apple. I like to use 'vhosts' instead of 'sites'.
    Then just add this to your httpd.conf...
    Include /private/etc/apache2/vhosts/*.conf
    I would keep a copy of your httpd.conf at all times. Apple likes to wipe that out on system updates.

  • Problem with 5.2 install - idsgroup does not exist

    All,
    I am trying to install Sun ONE Directory Server 5.2 on a new Cluster. The idsuser and idsgroup have been both setup with the id 10000.
    I have created a silent install file to work with the ./setup -noconsole -nodisplay -state silent.inf command.
    When I run the command as idsuser - but the setup command has been sudo-ed - I get the following error:
    Idsgroup does not exist.
    Ive done a grpck and a idchk and both have come back as being OK? Is there an issue where the install will only work if you run it as Root and not sudo-ed?
    Both group and idsuser show in the correct way in /etc/group and /etc/passwd.
    Any ideas would be gratefully received as this is now becoming quite urgent.
    Thanks
    og

    All,
    I am trying to install Sun ONE Directory Server 5.2
    on a new Cluster. The idsuser and idsgroup have been
    both setup with the id 10000.
    I have created a silent install file to work with the
    ./setup -noconsole -nodisplay -state silent.inf
    command.
    When I run the command as idsuser - but the setup
    command has been sudo-ed - I get the following
    error:
    Idsgroup does not exist.
    Ive done a grpck and a idchk and both have come back
    as being OK? Is there an issue where the install will
    only work if you run it as Root and not sudo-ed?
    Both group and idsuser show in the correct way in
    /etc/group and /etc/passwd.
    Any ideas would be gratefully received as this is now
    becoming quite urgent.
    Thanks
    ogHi ,
    Did you get this figured out yet? I'm facing the exact same problem. Doesn't seem to make any sense.
    Thanks,
    Tito

  • TS3960 After upgrading to Lion server 10.7.4, Server.app does not start.

    I upgraded from 10.6.8 Server.  The Mac OS 10.7.4 starts fine, but when attempting to launch 'Server' (which does appear in the launchpad) nothing happens (the application does not start).
    I checked for this:
    sh-3.2# sudo launchctl list | grep -q com.apple.servermgrd && echo loaded || echo not loaded
    loaded
    Thank you in advance for any help on this front. AV

    I got solution.After I reset the Server.App i could able to login the Server.App.
    For reference : http://krypted.com/mac-os-x-server/hosed-your-mountain-lion-server-reset-it/

  • Problems with the Cisco NAC agent, does not perform remediation??

    Good Morning
    I'm doing an implementation of NAC, but when the user is authenticated, the agent informs you that does not comply with defined security policies, to start the repair and re-scan the machine error appears "NAC Server is not available on the net" . The policy I am doing is to check a file on local disk C
    Deputy error screen
    I appreciate your responses as soon as possible

    the problem i have is when it moves into remediation....phase 2. If no remediation is being done (ie no checks, rules scans etc) then it moves directly from phase 1 (authentication) to phase 3 (authenticated user and assign role) and all works fine.
    I've looked under all the traffic rules and can see nothing that would mean it could not contact the CAS. There are some differences in 4.7, like the ethernet traffic filter. It seems to me when put in the temp role, the vlan should still be the auth vlan. There is a role based vlan option under edit roles, but it states that is only for normal login, not tem agent, so it should not apply.
    Im starting to think something has gone wrong with the upgrade code somewhere....TAC looked at my config  and could see nothing on a quick check, im working with them to resolve the issue

  • Problem with waveform chart: time scale does not show time correctly

    Hello,
    I have some problems with a chart.
    I want to display some data and the time between two single data can vary. It is something between 50ms and 500 ms.
    The problems I have:
    1. The time is not shown correctly in the chart (allways 2:00:10 instead of the current time)
    2. the data points in the chart have a distance of 1 s (x-scale). That is not correct.
    I have tried several things but I thinkt I am on the wrong track.
    Could you please help me?
    Johannes
    LabVIEW 7.1 (!)
    Message Edited by johanneshoer on 10-14-2009 04:26 AM
    Greetings Johannes
    Using LabVIEW 7.1 and 2009 recently
    Solved!
    Go to Solution.
    Attachments:
    Chart Test.vi ‏55 KB

    I have modifierd the vi again.
    Now it looks much better.
    I have a data array and the last 10 seconds of the data are displayed.
    The array size is maximum 150 and that is more than I need to display. If new data is inserted, the oldest gets deleted.
    I wonder if this style is efficient?
    The time is stil not displayed correctly in the graph. Why does it always show 2:00:00 ?
    Johanens
    LabVIEW 7.1
    Greetings Johannes
    Using LabVIEW 7.1 and 2009 recently
    Attachments:
    Chart Test 3.vi ‏57 KB

Maybe you are looking for