SocketChannel - problem. Can only read once.

Hi!
I'm having some trouble with my accepted SocketChannels from a ServerSocketChannel. The first transmission from the remote host after it has been accept()'ed (I'm using telnet on another mashine to test it) works just fine. But that's it, then I get no more information from the remote host, no matter how much I try.
I find this very strange, and completely without any reason.
I've found out that my connection never causes selector.selectNow() to return > 0 after the first transmission, unless there's some other activity but my connection I described above. It doesn't even detect when I close the connection from my telnet-client.
These three methods are the only one who actually handles ServerSocketChannel and SocketChannel, feel free to help me out =]
Thanx in advance
   * Thread method, listens for socketrelated events.
  public void run()
    try
      while (true)
        if (selector.selectNow() > 0)
          Set selection = selector.selectedKeys();
          Iterator selectedkeys = selection.iterator();
          while (selectedkeys.hasNext())
            SelectionKey key = (SelectionKey)selectedkeys.next();
            try
              if (key.isReadable())
                read(key);
              else if (key.isConnectable())
                finishconnect(key);   
              else if (key.isAcceptable())
                accept(key);
            catch (CancelledKeyException e)
              System.out.println("SelectionKey has been cancelled:");
              e.printStackTrace(System.out);
        else        // If no selection was made, sleep for
        {           // a while to let the processor get some rest =]
          try
            Thread.sleep(50);
          catch (InterruptedException ignore) { }
    catch (ClosedSelectorException e)
      System.out.println("Selector has been closed:");
      e.printStackTrace(System.out);
      System.exit(1);
    catch (Exception e)
      System.out.println("An unforseen error has occurred:");
      e.printStackTrace(System.out);
      System.exit(1);
   * Reads from the socket, and puts it in a ByteBuffer.
   * @param key The selected key from the selector.
  private void read(SelectionKey key)
    try
      SocketChannel socket = (SocketChannel)key.channel();
      Connection conn = (Connection)key.attachment();
      int bytes_read;
      while ((bytes_read = socket.read(buffer)) > 0)
        buffer.flip();
        conn.incoming(buffer);
        buffer.clear();
      if (bytes_read == -1)    // Socket closed.
        try
          key.cancel();
          socket.close();
        catch (IOException ignore) { }
        conn.disconnected("Connection closed by remote host.");
    catch (IOException e)
      System.out.println("I/O exception occurred while reading from socket: " + e);
      e.printStackTrace(System.out);
   * Accepts, and handles incoming sockets from the ServerSocketChannel.
   * @param key The selected key from the selector.
  private void accept(SelectionKey key)
    try
      ServerSocketChannel server = (ServerSocketChannel)key.channel();
      SocketChannel socket = server.accept();
      if (socket != null)
        socket.configureBlocking(false);
        SSConnection ssc = (SSConnection)key.attachment();
        ConnectionListener listener = ssc.getListener();
        int mode = ssc.acceptConnection();
        Connection conn;
        if (mode == ISO_LATIN_CONNECTION)
          conn = new TextConnection(socket, listener, true);
        else
          conn = new Connection(socket, listener, true);
        socket.register(selector, SelectionKey.OP_READ, conn);
        ssc.connectionAccepted(conn);
    catch (IOException e)
      System.out.println("Failed to accept incoming connection:");
      e.printStackTrace(System.out);
  }

It's opened in the constructor:
   * ConnectionManager - constructor.
   * Opens a selector and starts the thread for this object.
  private ConnectionManager()
    try
      selector = Selector.open();
    catch (IOException e)
      System.out.println("Error occurred while opening selector: " + e);
      System.exit(1);
    new Thread(this).start();
  }

Similar Messages

  • The same user can only login once

    Hello,
    I have a problem with my system. I made a system where you must login.
    I use the following code:
    boolean login = false;
    String username= request.getParameter("username");
    String password= request.getParameter("password");
    User user= Usermutations.makeviaUsername(username);
    if (user.getPassword().equals(password) && !password.equals("")) login= true;
    if (login) ReqD = getServletContext().getRequestDispatcher("/Overview.jsp");
    else ReqD = getServletContext().getRequestDispatcher("/False.jsp");
    request.getSession().setAttribute("user",user);
    request.getSession().setAttribute("username",username);
    request.getSession().setAttribute("password",password);
    if (ReqD != null) ReqD.forward(request,response);
    //Clean up resources
    public void destroy()
    Now I want that the same user can only login once. So when a user login with his username and password, no one else can login with that user name and password.
    I don't wan't to put the username in the database and then validate if the user is already logged in, because then the user must logout and not close the webbrowser else the user stays in the system.
    Does anyone knows a solution top this problem.
    Thanks in advance,
    Henk

    So I wan't the database and when the user is logged in
    the name is set in the database. But when the user
    clicks on the X (close button in the browser his
    username must be deleted from the database)You can't tell when the user does that (or perhaps you can sometimes, with difficulty). But even if you could it doesn't solve your problem. Many people keep their browsers open all day, and -- you may find this shocking -- they go to sites other than yours.
    So basically, if you don't provide them with a logout button you can't tell when they "leave" your site. And even if you do provide them with a logout button, they won't necessarily bother to use it. So you're left with waiting until the session expires, and then logging them out. This also means that if they come back to your site while the session is still active, then they are still logged in. This is not an error and you should not treat it as one.
    PC²

  • I have an external hard drive, from Iomega. However, I cannot copy or save any file to it. On my PC it says that is possible to read and write in it, but in my Mac, it says I can only read. can somebody help me?

    I have an external hard drive, from Iomega. that I can open and see my files. However, I cannot copy or save any file to it. On my PC I have it says that is possible to read and write in it, but in my Mac, it says I can only read. can somebody help me?
    Also, Im a photographer, so I like to name a lot of files at the same time (used to do in on PC and it was very usefull.) cannot find out how to do it on my Mac. Really appretiate if some one can give me a solution! Thanx

    Your drive is formatted with the NTFS file system.  OS X can read but not write to the NTFS file system.  There are third party drivers available that claim to add the ability to OS X to write to an NTFS partition.  I have not tried them and don't know if they work.
    The only file system that OS X and Windows can both write to natively is the FAT32 file system.

  • Is it possible for a mac to run across a Windows based server such as in a school, and still be able to access all networked folders? I have been told that macs can only read down a certain number of folders

    Is it possible to run a mac on a windows based server? We have a server based on Windows 7 in our school, and our techies are reluctant to let me buy a mac as they say macs can only read a number of folders deep, which would preclude me from accessing shared folders on our servers. Is this true, and is there a way round this? I would eventually like to get a suite of macs, but because all our resources are on the server, I have to be able to access them.
    Thanks for any help,
    Mike

    I have found that both Linux and Mac (unix) are capable of reading "deep" folders while win 32 will have issues, your it people are clearly wrong.  I run a network with both win/mac. And as long as the win servers/pc's that have shares are set to allow apple file sharing in their folder properties.   And the macs are set to allow smb there should absolutely no trouble with you accessing anything across the platforms, heck, from a Mac to a win pc on some occasions you don't even need to include a "domain" name to log on to, and you can create aliases and make your own shortcuts etc... So you don't have to manually connect each time you boot up etc... But that's all personal preferences I suppose.
    All I can tell you is that, I do it on a daily basis managing a small business. So your answer is yes you can.

  • Iomega "You can only read" permissions issue

    How
    How do I change "Sharing & Permissions:" from "You can only read" to Read & Write on my backup Iomega like the rest of my mac?

    Open the Disk Utility in the /Applications/Utilities/ folder and run the Repair Disk command on it. If the issue persists, add yourself in the Sharing & Permissions section.
    (71696)

  • I can only read e-books on my laptop. How do I get them unto my e-reader? It has something to do with the Adobe ID.

    Hello,
    just now I downloaden an e-book from the library and I wanted to copy it to my e-reader. I needed an Adobe ID but I forgot my password (and the website to get a new password wasn't working) so I clicked on 'open without authorization' but now I can only read the book on my laptop and not copy it unto my e-reader. Anyone an idea how I can  undo this? Because I did manage to retrieve a new password.
    Thanks for your help!

    It need to be removed from the computer you sold with it activated on. If you want to use that activation on a different computer. If you wiped that computer you need to contact Adobe this is a user forum users here do not have access to Adobe Activation servers and databases.

  • My external harddisk formatted in one iMac can only read in other iMac. How to make enable read

    Why my external harddisk formated as R&W for one imac will remained for use in that imac only. When I bought a new imac the external hard disk end up can Read only. Shouldn't it remain the same as R&W? There is no way you can set back to R&W for my new imac. Why can't Apple make thing simple for us and let the complicated user do the complicated thing? Once formated it should be able to use for all PC and all Mac. How to reset without lossing all my files in the harddisk? I know the easiest way to reset is to reformat it and lose everything. Not user friendly isn't it?

    Jimmykkk,
    If you want assistance you need to quit the rant and state what you need. Also be specific, you don't mention anything about the old Mac, the kind of EHD, what it is used for etc....
    If you want to share a EHD between a PC and Mac you will have many limitations,  primarily the size of files you can store.

  • Weird Problem - can only see Mac in "Share my Screen"

    I've been having a strange problem that I think might have something to do with OpenGL, but I'm not sure. I think it might be because I've gotten some error messages that said that OpenGL wasn't available or working properly.
    When I boot my mac, I have a hugely corrupted screen (gray with green stripes) which doesn't change at all. However, I can hear things starting up, and when I use "Share my Screen" from my MacBook, I can see everything, and the computer runs just fine.
    I've tried attaching a different monitor; it looks exactly the same, and both monitors run perfectly when attached to other computers.
    I tried taking out all the cards and things, wiping everything down, and putting them back. No change.
    I tried booting in Safe Mode. It never actually booted. (I left it to try for about 20 hours before I gave up.)
    I've tried resetting the PRAM, and that didn't help. (Before that, I had scattered green dots, and a fractured apple logo, with the widget that showed the computer was loading, until the point where the screen should turn blue, when it would freeze. Now I just have green stripes.)
    I've tried to reinstall the original system, but when I attempt to boot from the CD, I get a kernal panic. This is true, no matter what CD I attempt to boot from.
    I've opened the computer as a Firewire Drive (using an older Macbook) to change the system from there; but you can only install the stystem on the boot drive from the disks I have. While I was running it like this, the Firewire icon showed up just fine on my monitor, white on the gray with green stripes.
    I've tried upgrading to Lion (I was using Snow Leopard) and was able to do it, but that didn't solve anything.
    I don't appear to have the Lion reboot partition. At least, if I do, I don't know how to find it. The keyboard shortcuts don't do anything as far as I can tell. Since I cannot actually see anything on the screen until the comptuer is fully booted, so it might be there, but invisible.
    Unfortunately, I didn't try the old install disks until after the Lion upgrade. Now, if I try to just install from the disk (using Share my Screen, so I can see what I'm doing) I'm told that I can't.
    When I run Disk Utility, it says everything is fine.
    The computer is due to be replaced in October anyway. Should I just give up and get the new one now? Or can any of you think of anything else that I might be able to try? Everything is totally backed up, so if I need to wipe my disks, that's not a problem.
    The computer is a
         Mac Pro
         2 x 3 GHz Quad-Core Intel Xeon processor
         4 GB 800 MHz DDR2 FB-DIMM memory
         NVIDIA GeForce 8800 GT 512MB Graphics card
         OS 10.7.4
    Thanks for any help you can give me. I'm at my wits end!
    Robin

    Hi Robin,
    The no boot in Safe Mode is a big clue, generally a serious Hard Drive problem, but can be others.
    Are you saying the blotched screen showed up fine in Screen Sharing? If so the problem is downwind of the Video Card/VRAM, & you seem to have eliminated the Cable & Monitor, so I'd quess Logic Board most likely.
    On the HDD problem, try Zeroing the drive while it's in Target Mode...
    1. Insert the Mac OS X Install disc, then restart the computer while holding the C key.
       2. When your computer finishes starting up from the disc, choose Disk Utility from the Installer menu. (In Mac OS X 10.4 or later, you must select your language first.)
          *Important: Do not click Continue in the first screen of the Installer. If you do, you must restart from the disc again to access Disk Utility.*
       3. Click the Erase tab.
       4. Click the disclosure triangle to the left of the hard drive icon to display the names of your hard disk volumes and partitions.
       5. Select that iMac volume.
       6. Highlight the drive, select Partition Tab, then Format type... MacOS Extended Journalled, select the Security Options button, choose Zero Out Data one pass, Erase... after completion do a new install... after completion hopefully you'll be able to get a good install.

  • New problem - can only connect w/o security

    have a wireless router and had no problem getting my macbook to connect. added a desktop and can only connect if i disable the password feature. my question is twofold:
    1. why will it not connect when I have to supply a password (the password is correct)
    2. if I cannot resolve issue 1, then can I diable SSID broadcast but still not require a password?

    Try to include a dollar sign before your password

  • It can only read the enhanced portion of CDs

    When ever I put in an enhanced CD (an album with extra media, like music videos, or web links) it only reads that part of it, not the actual music files. Is there a way I can set up in prefrences to access both the audio and multimedia?

    It should display both the music and the enhanced media files, but if you have your setting in sys prefs like this
    it will work as you want it to.

  • Can Only Read Certain Discs

    I don't use discs very often, but recently I noticed that my macbook pro is unable to read a lot of my discs. The machine will accept the disc, whirr for a while, then eject it without seeming to recognize it. This is especially confusing as I know it was able to read some of these specific discs last year.
    After some experimentation I realized that the discs that DO work seem to have some of the center area filled in with extra data storage. After looking up the fact that the data on a disc starts at the center, the issue becomes clear: the machine tries to start reading at this smaller diameter and gives up without checking further out.
    Is my optical drive broken or is this a problem with the OS?

    Aidinthel wrote:
    I don't use discs very often, but recently I noticed that my macbook pro is unable to read a lot of my discs. The machine will accept the disc, whirr for a while, then eject it without seeming to recognize it. This is especially confusing as I know it was able to read some of these specific discs last year.
    After some experimentation I realized that the discs that DO work seem to have some of the center area filled in with extra data storage.
    There is no "extra data storage". It's just a label.
    Basically, your drive detects disc insertion, attempts to read the disc, and doesn't get a useful result. It concludes that the disc is damaged or incompatible and it spits it out. Assuming that these discs are clean and undamaged (that includes the label side), here's what could be going on
    (1) With age, the drive's laser beam can no longer focus very tightly. It can still read some discs, but fails with others. Unfortunately, you cannot check this unless you're technically inclined and have an oscilloscope. If your drive is 5 years or older, this is a distinct possibility.
    (2) Dust or other particles can settle on the drive's lens; this scatters the laser beam, with the same effect as in (1). You cannot check this with the naked eye, but you can try to fix it. There are special cleaning discs designed for this purpose. I cannot recommend any brand or model, but you can find them in them in the usual places (electronics stores, Amazon, etc). Make sure to read reviews of other users before buying and using such a disc.
    (3) Manufactured optical discs usually have a metal reflecting layer. When correctly manufactured, such a disc lasts a long time. But recordable media (CD-R, DVD-R, DVD+R, etc) employ a dye, which, even when new, has less contrast between 'pits' and 'lands'. In time, this contrast fades even more, so eventually the disc becomes unreadable and the data is lost. There can be considerable variation in the durability of recordable media. Some cheap, low quality discs can become unreadable even within a year.
    So, first check your media. Are the unreadable discs factory-made or recordable media? If the drive has problems with factory-made discs, first, make sure that the discs are good (other drives can read them); if they are, try cleaning your drive. If cleaning your drive hasn't worked, then it may be time to replace it with a new drive.

  • SQL Server 2014 can only backup once after restart. Subsequent backups fail

    Obvious response...install SP1

    Here is an odd one. I have SQL Server 2014 (not sp1) running in a cluster. Everything seems to be working fine. No performance issues or no crashes/error log issues.However, I can only backup a DB once after I restart (not reboot OS) SQL Server. If I try to backup the db a second time it fails, does not matter if I wait minutes, hours or days. I have tried switching backup locations and even have tried backing up to our Azure account. They all work the first time and fail on the subsequent attempts.Both machines are fully updated Windows Server 2012 R2. The only update available is SP1 for SQL Server. The failover is a Hyper V, while the active node is a physical server.Below is the error I get, which does not give me much detail. Any thoughts would be much appreciated. It is a pain to have to restart each night and manually backup the...
    This topic first appeared in the Spiceworks Community

  • Encoding Problem - can't read UTF-8 file correctly

    Windows XP, JDK 7, same with JDK 6
    I can't read a UTF-8 file correctly:
    Content of File (utf-8, thai string):
    เม็ดเลือดขาว
    When opened in Editor and copy pasted to JTextField, characters are displayed correctly:
    String text = jtf.getText();
    text.getBytes("utf-8");
    -32 -71 -128 -32 -72 -95 -32 -71 -121 -32 -72 -108 -32 -71 -128 -32 -72 -91 -32 -72 -73 -32 -72 -83 -32 -72 -108 -32 -72 -126 -32 -72 -78 -32 -72 -89
    Read file with FileReader/BufferedReader:
    line = br.readLine();
    buffs = line.getBytes("utf-8"); //get bytes with UTF-8 encoding
    -61 -65 -61 -66 32 0 64 14 33 14 71 14 20 14 64 14 37 14 55 14 45 14 20 14 2 14 50 14 39 14
    buffs = line.getBytes(); // get bytes with default encoding
    -1 -2 32 0 64 14 33 14 71 14 20 14 64 14 37 14 55 14 45 14 20 14 2 14 50 14 39 14
    Read file with:
    FileInputStream fis...
    InputStreamReader isr = new InputStreamReader(fis,"utf-8");
    BufferedReader brx = new BufferedReader(isr);
    line = br.readLine();
    buffs = line.getBytes("utf-8");
    -17 -65 -67 -17 -65 -67 32 0 64 14 33 14 71 14 20 14 64 14 37 14 55 14 45 14 20 14 2 14 50 14 39 14
    buffs = line.getBytes();
    63 63 32 0 64 14 33 14 71 14 20 14 64 14 37 14 55 14 45 14 20 14 2 14 50 14 39 14
    Anybody has an idea? The file seems to be UTF-8 encoded. What could be wrong here?

    akeiser wrote:
    Windows XP, JDK 7, same with JDK 6
    I can't read a UTF-8 file correctly:
    Content of File (utf-8, thai string):
    เม็ดเลือดขาว
    When opened in Editor and copy pasted to JTextField, characters are displayed correctly:
    String text = jtf.getText();
    text.getBytes("utf-8");
    -32 -71 -128 -32 -72 -95 -32 -71 -121 -32 -72 -108 -32 -71 -128 -32 -72 -91 -32 -72 -73 -32 -72 -83 -32 -72 -108 -32 -72 -126 -32 -72 -78 -32 -72 -89 These values are the bytes of your original string "เม็ดเลือดขาว" utf-8 encoded with no BOM (Byte Order Marker) prefix.
    >
    Read file with FileReader/BufferedReader:
    line = br.readLine();
    buffs = line.getBytes("utf-8"); //get bytes with UTF-8 encoding
    -61 -65 -61 -66 32 0 64 14 33 14 71 14 20 14 64 14 37 14 55 14 45 14 20 14 2 14 50 14 39 14
    buffs = line.getBytes(); // get bytes with default encoding
    -1 -2 32 0 64 14 33 14 71 14 20 14 64 14 37 14 55 14 45 14 20 14 2 14 50 14 39 14
    Read file with:
    FileInputStream fis...
    InputStreamReader isr = new InputStreamReader(fis,"utf-8");
    BufferedReader brx = new BufferedReader(isr);
    line = br.readLine();
    buffs = line.getBytes("utf-8");
    -17 -65 -67 -17 -65 -67 32 0 64 14 33 14 71 14 20 14 64 14 37 14 55 14 45 14 20 14 2 14 50 14 39 14
    buffs = line.getBytes();
    63 63 32 0 64 14 33 14 71 14 20 14 64 14 37 14 55 14 45 14 20 14 2 14 50 14 39 14 These values are the bytes of your original string UTF-16LE encoded with a UTF-16LE BOM prefix.
    This means that there is nothing wrong (the String has been read correctly) with the code and that your default encoding is UTF-16LE .
    Edited by: sabre150 on Aug 1, 2008 5:48 PM

  • T400 DVD RW recording problem, can only record via win7 explorer

    After upgrading the T400 from Vista business to Win7 pro,
    all my cd/dvd recording software solutions do not seem to work any more.
    Nero, Ultimateburner, cdburnerxp , deepburner +++ all can see the
               HL-DT-STDVDram GSA-u20n hx12 drive
    but can not burn anything. Finds it to e a Read only Drive ?
    However, win7 explorer can burn files etc
    without any problem. Never ever had this problem before.
    Anyone else had tis problem ?
    I've tried to locate an updated driver but have not suceeded yet
    All hints and ideas are very welcome.

    Have you tried your original Roxio Business Creator software with Windows 7?

  • "You can only read" when Read & Write assigned

    The "Backups.backupdb" automatically created on my external hard drive for Time Machine is the folder in question.
    I am changing the icons on my EHD folders and it has worked fine for every other folder, because I created them myself of course.
    There is no problem with the Time Machine folder and all my backups are perfectly accessible and everything.
    All I want to be able to do is change the icon from the blue folder but I have this problem that I can read only even after I've assigned read and write permissions to myself :/
    Can anybody help?

    Never log in as root. Do not enable it. There's nothing you can't do from the Terminal with admin rights.
    Open the Terminal. Enter the following text, or copy/paste it from here:
    sudo rm -R
    Do not press enter yet. Put a space after the -R, then drag and drop the folder into the Terminal window. It's path and name will be added to the end of your command. Now press enter. Terminal will ask for your admin password. Type it in and press enter. The folder should be removed.

Maybe you are looking for

  • The sound of podcasts are distorted when I download them to my ipod touch.  How do I fix/ prevent this?

    The sound is fine on my computer, but when I sync them with my ipod they are distorted.  Why?  How do I fix this?

  • Chapter Marker to stop play

    Hi guys- Forgive me if this is in the manual or in a thread, wasn't sure what to look up. I have a movie that contains clips A, B, and C. Step 1 is to make chapter markers for A, B, and C. Then, I would like to have, say, a chapter maker that would s

  • How to pair my white apple remote with my macpro?

    this is the kind of mac I have G87151S7UQ2 (I think?) its a tower pro, and I'd like to pair my white apple remote with it Thank you!

  • Error installing FMLE 3.2

    I've tried a variety of ways to install Flash Media Live Encoder 3.2 and it won't mount to my mac. When I run the installation program, it intializes, the bar progresses to 100% and the nothing happens. Upon examing the system log and terminal codes,

  • New multi-platform Mobile Flex app development

    I thought I'd post this note to encourage anyone that hasn't tried multi-platform Mobile Flex application development yet. Inside 4 weeks, I managed to get this application up on both the Android and Apple app stores: http://itunes.com/apps/trontextf