Socket Channel

Hi,
I have a appication uses ServerSocketChannel at the server side and socket at the client side. I am using selector to read the requests that comes to the server. And I am using three ports, each for a separate operation. One such port is meant for streaming purpose. That is when the client requests foe a particular stream from IP Camera, the server gets the requests and gives streams in response.
My problem is that, when I connect more than one camera, I gets streams intermixed. The streams are intermixed only when using a high speed network. How can I find a solution to this problem.
Thanks

How can I find a solution to this problem. As a start, you might want to post to a more appropriate forum, such as
http://forum.java.sun.com/forum.jspa?forumID=11

Similar Messages

  • Reading lots of bytes from a socket channel

    Hello,
    I have a client/server architecture.
    My server writes() to a socketChannel the contents large byteBuffer.
    On my client, I read() the socketChannel in to a byteBuffer. However, the data I wrote to the socketChannel is so large that it doesn't all arrive in one read(). I get a byteBuffer, but it isn't complete.
    Is there any way to know that there is more data waiting on the socketChannel, as it were? Or do I need to handle this myself by keeping track of the number of incoming bytes?
    Cheers!

    I was wondering whether Java had any kind of internal way of saying "I've not yet finished writing what I was told to write....there's more data to come".Socket.Channel.write() returns a byte count. If it's less that you expect, the write was incomplete.
    I suspect the answer is "no"No, the answer is 'yes', unless you are ignoring the return value.
    The canonical way to write a buffer is this:
    while (buffer.position() > 0)
      try
        buffer.flip();
        int rc = channel.write(buffer);
        if (rc == 0)
            // Here you must register the channel for OP_WRITE
            // and wait for it to trigger before trying again, not shown.
            key.interestOps(SelectionKey.OP_WRITE);
            break;
      finally
        buffer.compact();
    if (buffer.position() == 0)
      // The entire buffer has been written.
      // At this point you deregister the channel for OP_WRITE,
      key.interestOps(0);
      // or more probably re-register for OP_READ.
      key.interestOps(SelectionKey.OP_READ);
    }

  • Using a selector to detect closed socket channel.

    Basically our app uses one thread to perform a select on multiple socket channels. When a socket is closed (either remotely or locally) the server app needs to unregister the client (so we need to detect closed channels). We've been using blocking IO previously (no dramas), but now we're dealing with many connections/clients we need to rework it as we're getting excessive amounts of threads. Anyway, that's just background.
    Here's the problem we're getting, I have boiled it down to the following.
    SocketChannel channel = SocketChannel.open();
    channel.connect(socketAddress); // for the test this is localhost.
    // this make sure socket is open, remote end just echos, waits 3 seconds and closes the socket.
    channel.write(ByteBuffer.wrap("testLocalSocketClose\n".getBytes()));
    channel.configureBlocking(false);
    Selector selector = Selector.open();
    LOG.fine("registering channel");
    channel.register(selector, SelectionKey.OP_READ, channel);
    LOG.fine("closing channel");
    channel.close();
    LOG.fine("waiting...");
    int i = selector.select();
    // this never happens (or it does very rarely)
    LOG.fine("selector woke with " + i + " selected");I would have expected the selector to return the selection key of the dead channel. Given that it doesn't and this scenario is possible (channel closing just after a read operation but before another select is called - in separate threads obviously). How can we reliably detect/be informed that the channel has been closed?
    (I saw somewhere someone mention adding the OP_WRITE to the key, I have tried this as well and it makes no difference).
    Many Thanks.
    Bob.

    May I suggest you look at your application and reassess; either it's wrong or it's your understanding of what our issue is.
    Please try the simple test below.
    WSADATA ws;
    WSAStartup(0x0101, &ws);
    SOCKET sock = socket(PF_INET, SOCK_STREAM, 0);
    struct sockaddr_in server;
    server.sin_family = AF_INET;
    server.sin_addr.s_addr = htonl(INADDR_ANY);
    server.sin_port = htons(9000);
    cout << "binding" << endl;
    bind(sock, (struct sockaddr *)&server, sizeof(server));
    cout << "listening" << endl;
    listen(sock, SOMAXCONN);
    struct sockaddr_in client;
    int client_size = sizeof(client);
    memset(&client, 0, client_size);
    cout << "accepting" << endl;
    SOCKET clientSock = accept(sock, (struct sockaddr*)&client, &client_size);
    // shutdown socket.
    cout << "shutting down client socket" << endl;
    shutdown(clientSock, SD_BOTH);
    // setup select
    FD_SET fd;
    TIMEVAL tv;
    FD_ZERO(&fd);
    tv.tv_sec  = static_cast<int>(6000);
    tv.tv_usec = 0;
    FD_SET(clientSock, &fd);
    cout << "selecting" << endl;
    int rc = select(0, &fd, NULL, NULL, &tv);     
    cout << rc << ", " << FD_ISSET(clientSock, &fd) << endl;
    char msg[500];
    if (FD_ISSET(clientSock, &fd)) {
         cout << recv(clientSock, msg, 500, 0) << endl;
         cout << WSAGetLastError() << endl;
    cout << "closing" << endl;
    closesocket(clientSock);Telnet to port 9000, you get the following output immediately:
    binding
    listening
    accepting
    shutting down client socket
    selecting
    1, 1
    -1
    10058
    closing
    The solution I posted previously re calling shutdownInput/Output in Java isn't correct however, I left OP_WRITE on by mistake, which always returns ready, my fault.  Apologies.
    Whatever the behaviour, it will be the same for Selector.select() as it is for select().
    Clearly not.
    Edited by: Bawb on 29-Jul-2011 07:01, I had left OP_WRITE on which was returning ready each time, when I realised and took it out I removed the shutdown code which made me think I hadn't sorted this. Apologies again.
    Still reckon an RFE for OP_SHUTDOWN should be added to Java.
    Thanks.

  • Reg. Socket Channel Write Method

    Hi,
    We have the following method to write into the socket channel.
         private void write(SelectionKey key)
              SocketChannel channel = (SocketChannel) key.channel();
              try
                   channel.write(writeBuffer);
                   key.interestOps(SelectionKey.OP_READ);
              catch (IOException ioEx)
                   LogUtility.log(Level.SEVERE, ioEx);
    My doubt is, in case of any network related issues and network goes down, how to trap those exception. In those cases, i need to re-establish the connection again to the remote host.
    I tried to check, whether channel.isConnected b4 writing, but the doc says this will return false if the connect operation is never fired.
    It will be helpful for me, if some one gimme an idea to proceed on this.
    Best Regards,
    K.Sathishkumar

    If you get any IOException or SocketException other than a SocketTimeoutException when doing I/O to a socket or SocketChannel you must close the socket/channel. It is of no further use. What else you do depends on the application - log it, maybe try to re-establish the connection if you are a client, forget about it if you are a server.
    BTW:
    We have the following method to write into the socket channel.
    private void write(SelectionKey key)
    SocketChannel channel = (SocketChannel) key.channel();
    try
    channel.write(writeBuffer);
    key.interestOps(SelectionKey.OP_READ);This is not valid. You shouldn't throw away the result of the write and just assume the data got written as you are doing here. You should do something like this:
    try
      // assuming the buffer is already flipped
      int count;
      while (writeBuffer.hasRemaining() && (count = channel.write(writeBuffer)) > 0)
      if (count == 0)
        key.interestOps(SelectionKey.OP_WRITE);
      else
        key.interestOps(SelectionKey.OP_READ);
    catch (IOException ioEx)
      LogUtility.log(Level.SEVERE, ioEx);
      try
        channel.close();
      catch (IOException ioEx2)
        LogUtility.log(Level.SEVERE, ioEx2);
    // ...}

  • IP of client in Server Socket Channel

    how could we find the IP of clients in TCP\IP NIO Channel....

    SocketChannel.socket().getInetAddress() on the accepted socket

  • Socket Channel Connection - Continuous read

    Hi all,
    I am new to socket programming. This is where I am stuck...I need to read from a channel 'continuously', i.e messages are continuous published and I need to keep on reading it. Below is my code for review....I am just getting the 1st line of the message. please suggest..Thanks in advance
    import java.io.IOException;
    import java.net.InetAddress;
    import java.net.InetSocketAddress;
    import java.nio.ByteBuffer;
    import java.nio.CharBuffer;
    import java.nio.channels.ReadableByteChannel;
    import java.nio.channels.SelectionKey;
    import java.nio.channels.Selector;
    import java.nio.channels.SocketChannel;
    import java.nio.charset.Charset;
    import java.nio.charset.CharsetDecoder;
    import java.util.Iterator;
    import java.util.Set;
    public class TestConnection {
         private static Charset charset = Charset.forName("ISO-8859-1");
         private static CharsetDecoder decoder = charset.newDecoder();
         public static void main(String[] args) throws IOException {
              SocketChannel sc = null;
              String desthost = "172.19.67.33";
              int port = 5002;
              InetSocketAddress isa = new InetSocketAddress(InetAddress.getByName(desthost), port);
              try {
                   sc = SocketChannel.open();
                   sc.connect(isa);
                   System.out.println(" Message--> " + readFromChannel(sc, 4096));
              } catch (Exception e) {
                   e.printStackTrace();
              } finally {
                   if (sc != null)
                        sc.close();
         public static String readFromChannel(SocketChannel sChannel, final int size) throws IOException {
              int numBytes = 0;
              boolean hasRead = false;
              ByteBuffer inBuffer = ByteBuffer.allocateDirect(size);
              CharBuffer charBuffer = CharBuffer.allocate(size + 100);
              StringBuffer dataRead = new StringBuffer();
              Selector selector = Selector.open();
              System.out.println(" Is Connected--> " + sChannel.isConnected());
              System.out.println(" sChannel.isBlocking()--> " + sChannel.isBlocking());
              sChannel.configureBlocking(false);
              System.out.println(" sChannel.isBlocking()--> " + sChannel.isBlocking());
              sChannel.register(selector, SelectionKey.OP_READ);
              try {
                   while (selector.select(20000) > 0) {
                        Set readyKeys = selector.selectedKeys();
                        Iterator readyItor = readyKeys.iterator();
                        while (readyItor.hasNext()) {
                             SelectionKey key = (SelectionKey) readyItor.next();
                             readyItor.remove();
                             ReadableByteChannel keyChannel = (SocketChannel) key.channel();
                             if (key.isReadable()) {
                                  for (int i = 0;; i++) {
                                       int count = 0;
                                       if ((count = keyChannel.read(inBuffer)) < 0) // EOF
                                            keyChannel.close();
                                            throw new IOException("Socket lost connection during read operation");
                                       numBytes += count;
                                       if (!inBuffer.hasRemaining()) {
                                            hasRead = true;
                                            System.out.println("has read");
                                            System.out.println("SUCCESSFUL, length of data read:" + numBytes);
                                            inBuffer.flip();
                                            decoder.decode(inBuffer, charBuffer, false);
                                            charBuffer.flip();
                                            selector.close();
                                            return dataRead.append(charBuffer).toString();
                                       if (i >= 2) {
                                            break;
                   if (false == hasRead) {
                        System.err.println("has _NOT_ read");
                        System.err.println("length of data read: " + numBytes);
                        System.err.println("length of data read: " + numBytes);
                        if (numBytes > 0) {
                             inBuffer.flip();
                             decoder.decode(inBuffer, charBuffer, false);
                             charBuffer.flip();
                             System.err.println("ERROR, data read: " + dataRead.append(charBuffer).toString());
                        throw new IOException("Socket read operation timed out");
                   } else {
                        throw new IOException("Invalid Read Socket state");
              } finally {
                   selector.close();
    }

    The output is -->
    Is Connected--> true
    sChannel.isBlocking()--> true
    sChannel.isBlocking()--> false
    has read
    SUCCESSFUL, length of data read:4096
    Message--> 000c100000300000007f100700302E12008071104060400 Lane Communication Is OK 004d100500300302E0100000027000000000000000000000000000010845800000000000000000000000c100000302E01007f100700303E12008071104140200 Lane Communication Is OK 004d100500300303E0402350427000000000000000000000000000119107300000008500000000000000c100000303E00007f100700304E12008070704085600 Lane Communication Is OK 004d100500300304E0201521427000000000000000000000000000081090700000003640000000000000c100000304E00007f100700305X12008071104111600 Lane Communication Is OK 004d100500300305X0801411215000000000000000000000000000048892600000000810000000001000c100000305X00007f100700306X12008071104102600 Lane Communication Is OK 004d100500300306X0800660815000000000000000000000000000046838800000000760000000000000c100000306X00007f100700307X12008063003542200 Lane Communication Is OK 004d100500300307X1000445315000000000000000000000000000125509000000017220000000127000c100000307X000104100300300307X200807111727309311015004453030200000000000000000000000000000527000001020102000000001154210344501304E2008071116072500EZPASS TAG# 022 - 04522780 STATUS = VALID TYPE = INTERIOR FPT Program Status = Success 00012550910000001723000000012820104100300300305X200807111727325610815014112010200000000000000000000000000000000010201020102000000005146360015500121E2008071117010800MANUAL CASH IN EXIT MANUAL 00004889270000000082000000000100104100300300307X200807111727353911015004453030200000000000000000000000000000072000001020102000000001154220344700103E2008071117070600EZPASS TAG# 008 - 03623801 STATUS = VALID TYPE = INTERIOR FPT Program Status = Success 00012550920000001724000000012800104100300300307X200807111727379411015004453030200000000000000000000000000000072000001020102000000001154230344900401E2008071117181300EZPASS TAG# 006 - 00468916 STATUS = VALID TYPE = INTERIOR FPT Program Status = Success 00012550930000001725000000012800104100300300306X200807111727399610815006608010200000000000000000000000000000000010201020102000000000075910013300613E2008071117032500MANUAL
    The out actually gives multiple line...but what should be the approach to read line by line continuously and keep parsing them......
    kind regards

  • Socket Channels

    Hello
    Anybody, whose been working with the new J2SE 1.4 ... i have a question i was just glancing at the New I/O functionalities and its speaks pretty strongly about having SocketChannels, but i really couldnt make out any greater advantage it has over the Socket connections in J2SE 1.3.1.x ...
    Infact it seemed more overhead and operations when the ur still in the end reading and writing to the socket ... what superiority does a SocketChannel provide over its predecessor the Socket connection in terms of efficiency, socket queueing and its TCP capabilities.

    A SocketChannel as I see it, gives you access to both read and write with the same object, and you use a ByteBuffer when you want to read and write (the idea is to avoid garbage collection). There is a good resource here:
    http://www.javaworld.com/javaworld/jw-09-2001/jw-0907-merlin_p.html
    With the Selector, you don't need to create a new thread for each connection to your server, just one for each server should be enough (or maybe two, one that listens for connections, and one that notifies you when there are channels ready to be read from).
    The link above explains it quite well I think (with the lack of other resources about the nio packages).

  • Do I need to cancel the selection key when I close it's socket channel?

    I have a non blocking server implementation and I need to know is it mandatory to call SelectionKey#cancel after I have called the SocketChannel#close to it's channel? When I close the channel, will it cancel the key automatically or what if I don't cancel the key, how does it affect to the selector?
    JK

    Thanks ejp, you are right, it's documented in SelectableChannel not in SocketChannel. My mistake.

  • Socket channel read return

    client server java nonblocking SocketChannel
    at the server do writes using this:
    socketChannel.write(byteBuffer);
    At the client end do a read
    socketChannel.read(inBuffer);
    When does the client read method return ?. Assume inBuffer is empty and is bigger than byteBuffer. Does it wait until it gets all of a single write or if there is an internet delay does it return with only part of the write bytes?
    Can read return with only some of the bytes sent in a single write ?
    The point am getting at is can inBuffer after a read have 2 partial write packets, or several write packets with perhaps partial packets at the start and end ?
    thanks
    p butler

    With TCP/IP read() can return any number of bytes from 1 to the size of the buffer (also 0 bytes if you have a non-blocking socket). The sending operating system, the receiving operating system, and all routers/firewalls/etc in between can break up and/or combine writes any way they want to. TCP is a stream protocol, not a packet protocol; "packet" or write() boundaries are not preserved.
    There are a couple of common ways to send "packets":
    A line based protocol. Each "packet" is a single line of text. If the actual payload data can contain \r or \n characters, those need to be escaped with a suitable escape character. Other packet terminators can be used also. e.g. "\n.\n" (= a period on a line of its own.)
    Length+data. Before sending a "packet", send an e.g. 4-byte value that tells how long the packet is. In the receiver, read until you have that many bytes. Note that even the 4-byte length header can be split up so that you may need to do four read() calls to get them all! DataInputStream has a readFully() method, or you can write your own static utility; see reply 5 here: http://forum.java.sun.com/thread.jspa?threadID=677542

  • Problem with writing to a socket channel

    My situation is thus:
    I have a SocketChannel connected to a remote telnet server. I am using a keylistener to listen for the enter button on a jtextarea in order to send the contents of that jtextarea to the remote telnet server via socketchannel.write
    The problem is that when I have the code to do this located in a keyReleased event listener, it works fine. However, for other reasons, I really need it to be in a keyPressed event listener, and it fails silently when I put it in one.
    I have code both before and after the part of the listener that calls socketchannel.write that executes properly, and some debug code that shows that i am sending the bytes that I think that I'm sending, and the socketchannel.write call returns the correct integer to agree with the number of bytes I'm trying to send, but the remote server never actually receives those bytes. It would automatically send back a response if it did, and even beyond that, I get timed out for inactivity by the remote server even if i continuously hit enter to send data.
    The keylistener i'm using is a class extended from keyadapter. I can literally flip the function signature back and forth between keyReleased and keyPressed, and it works absolutely perfectly with keyReleased, and everything but the socketchannel.write works perfectly with keyPressed. I am at a complete loss as to why it works with one, and not with the other.
    Any insights?
    Thanks in advance.

    I have found an answer elsewhere.
    The problem was that, with keyReleased, the actual stroke of the enter key was being recorded before the text was being sent, so it had a \n on the end of it.
    The game required a terminator in order to be able to process the data I sent, and keyPressed wasn't generating one.

  • Multi-buffer socket channelling

    Why does this stupid pixel grabber copy the last row and put it at the beginning?!?!? I have no clue why?! Whenever i run the code, the display shows me that the bottom row of a picture is COPIED to the top row... I DIDN'T TELL IT TO DO THIS!!! please help
    public void sendData( SocketChannel sChannel)
              int w = image.getWidth();
              int h = image.getHeight();
              int array[] = new int[w*h];
              PixelGrabber pg = new PixelGrabber(image, 0, 0, w, h+1, array, 0, w);
              try
                  pg.grabPixels();
              catch (InterruptedException e)
              image.getRGB( 0, 0, w, h, array, 0, 0 );
              ByteBuffer dimensionsX = ByteBuffer.allocateDirect(32);
              ByteBuffer dimensionsY = ByteBuffer.allocateDirect(32);          
              ByteBuffer bufAlp = ByteBuffer.allocateDirect(w*h);
              ByteBuffer bufRed = ByteBuffer.allocateDirect(w*h);
              ByteBuffer bufGre = ByteBuffer.allocateDirect(w*h);
              ByteBuffer bufBlu = ByteBuffer.allocateDirect(w*h);                    
             try
                  dimensionsX.put( (byte)w );
                  dimensionsY.put( (byte)h );
                  //System.out.println( dimensionsX.get(0)&0xff );
                  int g = 0;
                  while ( g < array.length )
                       bufAlp.put( (byte)((array[g]>>24)&0xff) );
                       bufRed.put( (byte)((array[g]>>16)&0xff) );
                       bufGre.put( (byte)((array[g]>>8 )&0xff) );
                       bufBlu.put( (byte)((array[g]    )&0xff) );                   
                       System.out.print( "(" + (bufAlp.get(g)&0xff) + ","
                                           + (bufRed.get(g)&0xff) + ","
                                           + (bufGre.get(g)&0xff) + ","
                                           + (bufBlu.get(g)&0xff) + ")" );
                       g++;
                  bufAlp.flip();
                  bufRed.flip();
                  bufGre.flip();
                  bufBlu.flip();             
                 dimensionsX.flip();
                 dimensionsY.flip();             
                 int nbw = 0; //number of bits written
                  nbw = sChannel.write(dimensionsX);
                  nbw = sChannel.write(dimensionsY);
                  nbw = sChannel.write(bufAlp);
                  nbw = sChannel.write(bufRed);
                  nbw = sChannel.write(bufGre);
                  nbw = sChannel.write(bufBlu);              
             catch (IOException e)
         }

    (a) Are you getting an IOException? Don't ever write empty catch blocks like that.
    (b) Are you in non-blocking mode?
    (c) Are you checking the return value of all the writes? There's no guarantee that all the data gets written.

  • File descriptor leak in socket programming

    We have a complex socket programming client package in java using java.nio (Selectors, Selectable channel).
    We use the package to connect to a server.
    Whenever the server is down, it tries to reconnect to the server again at regular intervals.
    In that case, the number of open file descriptors build up with each try. I am able to cofirm this using "pfile <pid>" command.
    But, it looks like we are closing the channels, selectors and the sockets properly when it fails to connect to the server.
    So we are unable to find the coding that causes the issue.
    We run this program in solaris.
    Is there a tool to track down the code that leaks the file descriptor.
    Thanks.

    Don't close the selector. There is a selector leak. Just close the socket channel. As this is a client you should then also call selector.selctNow() to have the close take final effect. Otherwise there is also a socket leak.

  • NIO issue - writing to sockets from 2 threads

    Hi All,
    I have some questions regarding a NIO-server i'm developing. I have read many posts relating this issue, but still...
    I have one thread that does the Selector.select() and read & write to the sockets
    I have another thread that uses the same Selector and changes the interestOp to OP_WRITE (then wakes up the Selector).
    I have a Connection (attachment) that i use to hold the inputBuffer and outputBuffer to handle remainings.
    I've read a post in which some ppl wrote the stages of using th OP_WRITE and it was suggested that only when i wanna write i'll add the OP_WRITE and exclude it in the isWritable() - so i'm doing that.
    My questions are:
    1. Is it safe to change the interestOp on a key from another thread?
    2. What happens if the select() is in process?
    3. Are there any other problems with my implementation?
    4. What other way i have to write to a socket from 2 different threads (withough putting a lock on the socket)?
    Thanks.

    Reset your thinking a bit. You should only register for OP_WRITE when you have just executed a 'short write', i.e. a return value > 0 but < the length you asked to write, and you should deregister OP_WRITE any time you execute a 'complete write', i.e. a write which writes everything you asked for. At all other times you should just write and handle your own syncrhonization. The reason is that socket channels are almost always writable except under the condition described so you will just be returning early from select() for nothing.

  • Java.nio.channels.IllegalBlockingModeException

    I am using selector for read and PrintWriter writer = new PrintWriter(new OutputStreamWriter(sc.getOutputStream()),true) for writing to the socket and I get this exception at write statement. Can anyone suggest me what should I do??
    java.nio.channels.IllegalBlockingModeException
    at java.nio.channels.Channels.write(Channels.java:59)
    at java.nio.channels.Channels.access$000(Channels.java:47)
    at java.nio.channels.Channels$1.write(Channels.java:134)
    at sun.nio.cs.StreamEncoder$CharsetSE.writeBytes(StreamEncoder.java:334)
    at sun.nio.cs.StreamEncoder$CharsetSE.implFlushBuffer(StreamEncoder.java
    :402)
    at sun.nio.cs.StreamEncoder$CharsetSE.implFlush(StreamEncoder.java:406)
    at sun.nio.cs.StreamEncoder.flush(StreamEncoder.java:150)
    at java.io.OutputStreamWriter.flush(OutputStreamWriter.java:213)
    at java.io.PrintWriter.newLine(PrintWriter.java:256)
    at java.io.PrintWriter.println(PrintWriter.java:405)
    at java.io.PrintWriter.println(PrintWriter.java:516)
    at SktChannelTest3.run(SktChannelTest3.java:91)

    Hi,
    Thanx for the reply. I am using Selecotor for read and if it timesout I used PrintWriter to write to Socket ( Not socket channel). So, once it comes out of select loop, it'd excecute PrintWriter.println("Timeout message....") statement. And at this statement I/m getting exception.

  • Working with NIO and non-NIO sockets

    Hello,
    Trying to write a network manager kind of program where the client initiates a number of connections to different servers. Need to manage these connections through the life time of the session ( time the client is connected to the server). The client connections originate from a single machine, the servers are geographically distributed and about 1 to 5 connections between each client and server.
    I have tried and example NIO client/server application and it works fine. I have tried the KnockKnock client/server example it works. But when I try to use the NIO client with the multithreaded knockknock server, the socket connection goes through okay. However the data written to socket channel on the client(NIO) side doesn't seem to reach the server(non-NIO). I can't change the servers since they already exist in the field. I am just trying to write the manager application to manage them.
    Basically I am trying to avoid writing a multithreaded socket connection management program.
    Thanks for any input.

    Not the greatest NIO code. The author seems unaware that closing a channel also cancels all its selection keys so he laboriously programs both operations every time he needs to close the channel. His discussion of OP_CONNECT makes little sense: the important point is that OP_CONNECT is only used in the connection phase and OP_WRITE is only used in the connected phase.
    His code registers the channel for OP_WRITE as soon as the connection completes, when there is no pending data to write. This will just cause the selector to spin uselessly doing nothing. The channel should be registered with zero interest-ops and OP_WRITE should be registered when there is something to write, i.e. during the send() operation; and it should be deregistered when the write has completed successfully and there is no more data to write.

Maybe you are looking for

  • How to get the running time on the page

    Hello , I want to display the running clock and the user who loggin in . Pls let me know how to get the running clock display and the username who log in. thakns kumar

  • Material document getting with mvt 552 during ticketing

    Hi, I am creating ticketing activities  for STO using movement scenario 16, with reference to the nomination i have posted two ticket documents, it had created the STO delivery in the back ground and material document also got created with movement t

  • Battery Indicator - won't turn off!!!

    Basically, my iPod won't/can't turn off. The little battery in the top right always has a little lightening bolt or plug in it, no matter if the iPod is plugged in or not. The obvious effect is that the battery runs down when I'm not "using" my iPod.

  • Error: PLS-00216: NUMBER precision constraint must be in range (1 .. 38)

    While compiling one package i am getting the error> PLS-00216: NUMBER precision constraint must be in range (1 .. 38) The declaration is: lServerImportRetVal          number(40); Database is Oracle10gdb. Do i resize the variable to 38... is that advi

  • First time updates cs5

    hi i have just purchesd photoshop cs5 extended and it has loaded correctly on my pc [windows7] i have tried to run first time updates,it keeps saying i have to close adobe bridge.ex first how do i do this thanks for any help you can give me.