NIO and traditional sockets

I have a little server that I was porting from traditional thread per socket programming to NIO. The first thing I ported was the Listen-Accept loop. This worked well but the resulting sockets obtained from
SocketChannel.socket()
have very strange behaviour with respect to flush. I send the data by
out.write(data);
out.flush();
where out is the BufferedOutputStream. The data doesn't get sent until the next input arrives on the Socket. If I change to using just old style I/O or completely NIO the problem goes away.
I found several bug reports on NIO and flush, but they all seem to be considered Feechures by SUN.

Thanks for posting the link to your NIO code. I downloaded the src-raining-1.2pre1 source and took a look. I noticed that you still have some doubts about how OP_WRITE works. This piece of code will definitely have problems.
    public void setSendData(ByteBuffer data) {
        this.write_pending = true;
        wBuffer = data;
        //RK modified on 20031008 23:19:39 - NOOO
                //registerChannel(selector, channel(), SelectionKey.OP_WRITE);
        // RK modified on 20031009 23:15:00 adding write interest
        SelectionKey sk = sc.keyFor(selector);
        int ops = sk.interestOps();
        sk.interestOps( ops | SelectionKey.OP_WRITE);
        selector.wakeup(); // is this required or not ???
    }The sk.interestOps will block if there is an active select. If there isn't an active select you don't need the wakeup. The only way to make this work properly in 1.4.2 is to build a queue of runnables that set interestOps and execute them just before or after the select. Also the setting of OP_WRITE in that code won't handle the case where the network exerts flow control on the channel. The correct setting of OP_WRITE is
- set interest in OP_WRITE when the socket is connected
- remove interest as soon as you successfully write all the data in a buffer
- add interest only when you write less bytes than requested.
My post Taming the NIO Circus provides an example of this in the swing based client. I posted this in response to Java.nio. SelectionKey interestOps(int) method blocks

Similar Messages

  • Using nio And udp

    My first question is. If my server is using nio datagramchanels, my client must use it too?
    can i use traditional datagram socket for comunicate with a nio udp server?
    I have much information on nio and tcp with examples that work. but i can't find examples of communication between client and server using nio UDP. Some page of reference or tutorial?

    My first question is. If my server is using nio
    datagramchanels, my client must use it too?No.
    can i use traditional datagram socket for comunicate
    with a nio udp server?Yes.
    I have much information on nio and tcp with examples
    that work. but i can't find examples of
    communication between client and server using nio
    UDP. Some page of reference or tutorial?You haven't looked very hard. Try 'NIO UDP example' on google.

  • What are the differences between Easy VSS and Traditional VSS on Catalyst 4500E with Sup 8E ?

    I would like to know which feature is different between Easy VSS and Traditional VSS.
    I know "Easy VSS is a new way of implementing VSS by using a single command" but I cannot find more information about it.
    Please help.
    Thank you.
    Nash

    Easy VSS is a simplified and automated way of configuring VSS for first time. Once a VSS is configured then it same as traditional VSS in functionality.
    There is no concept of layer 2 or layer 3 VSL link. VSL is the internal portchannel link and you cannot configure as layer 2 or layer 3 portchannel.
    Following is the link of Easy VSS steps.
    http://www.cisco.com/c/en/us/td/docs/switches/lan/catalyst4500/XE3-6-0E/15-22E/configuration/guide/xe-360-config/vss.html#60764

  • Differences between PSUs and traditional CPU patches

    Hi, this is Eric Maurice, Director Oracle Software Security Assurance. In the past, I have been getting a number of questions about the differences between the Patch Set Updates (PSUs) and traditional Critical Patch Update (CPU) patches.
    On August 11th at 11:00AM Pacific / 2:00PM Eastern, the Independent Oracle User Group (IOUG) will host a webcast on Database Server security patching featuring two speakers from Oracle: Bruce Lowenthal, Director for Security Alerts, and Lois Price, Director for Product Lifecycle Services.
    The purpose of this technical webcast is to discuss the various aspects of the Critical Patch Update (CPU) program, which are specific to Oracle Database Server. The speakers will spend a significant portion of the webcast discussing the differences between the Patch Set Update (PSU) and traditional CPU patches. An overview of the CPU program will also be provided, and ample time will be set aside for a Q&A session at the end of the presentation.
    The URL to register to this webcast is https://www1.gotomeeting.com/register/141106952
    For more information:
    Patch Set Updates for Oracle Products [ My Oracle Support Note 854428.1] is located at https://support.oracle.com/CSP/main/article?cmd=show&type=NOT&id=854428.1 (My Oracle Support subscription is required)
    The Critical Patch Updates and Security Alerts page is located at http://www.oracle.com/technology/deploy/security/alerts.htm
    Edited by: Eric P. Maurice on Jul 27, 2010 3:21 PM
    Edited by: Eric P. Maurice on Jul 27, 2010 3:22 PM

    Update:
    Due to technical difficulties, the Database Security Patching webcast, initially scheduled for August 11, 2010 at 1pm CDT has been rescheduled. The new webcast will take place on Wednesday, August 18 at 1pm Central.
    You can register again for this event at https://www1.gotomeeting.com/register/729035104

  • Non-global zones and unix sockets

    Hello, I have a problem with local zones and unix socket sharing. I've created directory in global zone for ex. /zones/shared. Added it to zones via 'add fs, type=lofs' . In one zone I'm putting mysql socket in it and I want that other local zones could use it. Is it possible to share socket between zones?
    After all my experiments I'm always getting 'can't connect to mysql ... (146)' , 146 is 'connection refused' error.

    These services are off-line in the non-global zone, which is why non of the
    rc2.d or rc3.d scripts are being run:
    offline Dec_12 svc:/milestone/multi-user-server:default
    offline Dec_12 svc:/milestone/multi-user:default
    Any idea how to enable these, and why they are offline?
    Michael
    Created a non-global zone on a Solaris 10 box.
    Boots up ok and I can login with zlogin.
    It doesn't seem to run any of the scripts in
    /etc/rc2.d or /etc/rc3.d
    I know Solaris 10 uses "Service Management Facility"
    for most services now,
    but could still run legacy scripts in /etc/init.d ?
    Also I can't get sshd to start on the non-global
    zone.
    # svcs -a |grep ssh2
    offline 11:44:58 svc:/network/ssh:default
    # svcadm enable -t svc:/network/ssh:default
    # svcs -a |grep ssh2
    offline 11:44:58 svc:/network/ssh:default
    Anyone got any ideas?
    Michael

  • IPhone 4s. IOS 7.1.1 Windows 7. Using same lead and usb socket. From yesterday my phone won't appear on computer. Will charge via usb lead. Dont have iTunes on this computer and never had.

    iPhone 4s. IOS 7.1.1 Windows 7. Using same lead and usb socket as always. From yesterday my phone won't appear on computer. Will charge via usb lead. Dont have iTunes on this computer and never had. Am now being asked if I trust this computer. This is new. Also takes longer than usual to signal it is charging. Get usual sound notification but nothing appear in computer. I long ago disables automatic notification that phone was connected. Prefer to bring it up manually.

    Within Contacts, tap Groups at top left. Make sure all contact groups are checked to show, then tap "Done" at top right.
    Within the Calendar app, tap Calendars at the bottom center of the screen. Tap on Show All Calendars.

  • Is there any incompatibility between Labview 8.5 and Traditional DAQ?

    Hi,  I`m using a DAQPad 6020E and the Labview 8.5 Daq assistant don`t detecte my DAQ when a try to create a new task (to create a new virtual chanel). But MAX detect the DaqPad. So, is ther any incompatibility between Labview 8.5 and traditional Daq? Do you know how can I resolve this?
    Thanks.

    First, you posted to the wrong board. Measure is an old add-on for Excel.
    Second, there is no incompatibility between LabVIEW 8.5 and tradtional DAQ. There is an incompatibility between traditional DAQ and DAQmx which is what the DAQ Assistant uses. Make sure that you install DAQmx if your device is supported by it. Otherwise, you will not be able to use the DAQ Assistant.

  • [svn:fx-trunk] 7795: fix locale names used in resource bundles for simplified Chinese and traditional Chinese  .

    Revision: 7795
    Author:   [email protected]
    Date:     2009-06-12 12:18:13 -0700 (Fri, 12 Jun 2009)
    Log Message:
    fix locale names used in resource bundles for simplified Chinese and traditional Chinese . zh_cn to zh_CN  and zh_tw to zh_TW
    bug: https://bugs.adobe.com/jira/browse/SDK-21174
    qa: localization team (yes)
    checkintests: pass
    Ticket Links:
        http://bugs.adobe.com/jira/browse/SDK-21174
    Modified Paths:
        flex/sdk/trunk/modules/compiler/build.xml

    I'm more of a 1.3 chick myself, but the words are the same just in a different language.
    1. Is Tomcat running?
    2. Have you configured the ajp13 connector on 8009 in Tomcat? (Should it be ajp13 for Apache 2.0? - I really must upgrade)

  • What NLS_LANG can handles both Simplified and Traditional Chinese?

    Hi,
    What values should I put into the NLS_LANG for my 10g db in order to handle English, Traditional and Simplified Chinese?
    Can I specify the date format during the db creation?
    Thanks

    You can try to create a database with database character set AL32UTF8. Then configure the NLS_LANG in client using the same character set. After that, try to input both simplified chinese and traditional chinese into one character column. See what is the results. I guess in AL32UTF8, same character has different encodings for simplified chinese and traditional chinese since they are written different ways.
    For date format, I don't think you need to take care the database date format. Internally, Oracle keep date values using numeric type. When I handle date values, I retrieve it using to_char(datavalule, 'yyyy-mm-dd') and update it back using to_date('2006-01-01', 'yyyy-mm-dd') ('2006-01-01' is just an example).
    G.B.

  • NIO and Windows

    Hallo,
    I have a strange problem with nio and windows. If want to map a MappedByteBuffer to a FileChannel (read-only).
    The file resides on a local hard drive.
    After doing my stuff, I close the FileChannel. But as long as the jvm is running,
    it is not possible to rename, delete or overwrite the file. (I'm using jre1.4.2 on Windows XP)
    If I don't map the FileChannel to the MappedByteBuffer I can delete the file after closing the FileChannel.
    If I call explicit the garbageCollector after using the MappedByteBuffer, I can delete the file, too.
    But I dislike the idea to call the garbage collector to be able (via a side effect) to delete the file. Isn't there a better way to send the MappedByteBuffer a message, that I don't need it anymore?
    Here is a test program to show my problem:
    package test;
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.nio.channels.FileChannel;
    /** This class shows a strange behaviour on the windows platform.
    public class NioTest {
         // The file must be on a local hard disk for the error to occure
         private final static File FILE = new File("C:\\map.txt");
         private static boolean withGC;
         public static void main(String[] args) throws IOException,
                   InterruptedException {
              withGC = args.length > 0;
              try {
                   while (true) {
                        if (FILE.exists()) {
                             System.out.println("File exist; try to overwrite");
                        } else {
                             System.out.println("File doesn't exist; try to create new one");
                        createFile();
                        lockingAction();
                        System.out.println("Seemed to work; try new iteration");
                        Thread.sleep(1 * 1000);
              } catch (IOException exp) {
                   exp.printStackTrace();
         private static void lockingAction() throws IOException {
              FileChannel channel = new FileInputStream(FILE).getChannel();
              channel.map(FileChannel.MapMode.READ_ONLY, 0, channel.size());
              if (withGC) {
                   // if garbage collector is called the exception doesn't occure
                   Runtime.getRuntime().gc();
              channel.close();
         private static void createFile() throws IOException {
              FileOutputStream out = null;
              try {
                   out = new FileOutputStream(FILE);
                   out.write("Test".getBytes());
              } finally {
                   if (out != null) {
                        out.close();
    }

    Thanks for your answer, I knew that already, but it is nowhere specified, that when the filechannel is mapped to a mapped byte buffer the file is locked.
    And this only occures on windows system and not on unix systems.
    There is no (?) api function to close the mapped byte buffer. All I can do is to wait that the mapped byte buffer is garbage collected. Then through the observed behaviour of the system the lock is released, but it is nowhere specified.
    Because the lock is released after the m.b.b. is garbage collected it seems that there is indeed some code which released the lock.
    Is there a possibility for the programmer to this functionality directly?

  • How can I creat virtual channel and traditional devices while my card installed,I can not do?

    I installed PCI-6220 card,and I also installed DAQmx and Traditional DAQ in my computer,
    but I cannot creat virtual channel at the last step(attachment:TDAQ6220.jpg).
    Maybe this is the reason I didn't creat traditional NI-DAQ Device,but I can not creat it.
    (see attachment: DAQ Device.jpg,there is no PCI-6220 on list).
    What's wrong?What shall I do?
    Junwei You

    Hello Rainer,
    You can see this attachment(6024E.jpg),the 6024E card appears on Traditional NI-DAQ Devices,
    but I don't know how can it be created(I don't creat it,we buy the whole system together with the machine).
    I tried create a new traditional Device(I want to confirm 6024E), but still I can not see any NI-DAQ device in traditional NI-DAQ device
    lists. See the 'Create New....' interface.How can do it?
    Thanks!
    Attachments:
    6024E.JPG ‏128 KB

  • Connecting case headphone and mic sockets to X

    I want to be able to connect my PC cases headphone and microphone sockets to my X-Fi (XtremeMusic). I can't use the dri've bay expansion box thing because I have a door on my case, and it's too expensi've anyway.
    The AD_EXT connection on the card has many pins. Would I be able to just connect up the pins that are used for mic and headphones
    Any ideas/advice?

    That question was answered many times around here, you need just to search...Message Edited by SoNic2367 on 07-25-2006 08:27 PM

  • MS-7025 and JUSB 1 and 2 sockets

    I'm going to buy a case that has front USB connectors
    and I plan to use the JUSB1 and JUSB2 socket.
    Are there any known issues?
    (I remeber reading something....)
    Thanks,
    Bill

    Check the wiring harness from the case(or rather the connector block from the case that connects to the USB header) and read the manual.
    Quote from: Frankeputer
    Check to see if there is a wire running from your Front USB ports to the #10 slot of your USB block which connects to the motherboard header.
    USB connector block layout which corresponds to the pin layout on boards with the Intel spec for USB. Do not cut the pin on the MOBO. You are removing/cutting the wire to the connector block from the case.
    2 4 6 8 10(this wire, #10, not needed)     
    1 3 5 7 9(filled/key)
    If you find a wire leading to the #10 spot on the block, remove that wire. My block has tabs so that you can pull the wire out, or you could snip/cut the wire leading to that position--if you cut the wire, be careful to cut the correct one and cut it in such a way that it may be repaired if you make a mistake.  Make sure you wrap the wire, the exposed end/s, you remove/cut with electrical tape so as not to accidentally cause a short. I actually folded the wire back and wrapped it.
    2 posts to read--Here and Here.
    This seems to be a common issue involving many different case manufacturers. I don't know how it applies to other MOBO manufacturers, but in these forums it is not limited to a specific MSI model or supported chipset(Intel or AMD).

  • Convert between simplified Chinese and traditional Chinese iWork 13

    In the latest version of iWork, services of converting between Simplified Chinese and Traditional Chinese doesn't work any more. Does it happen to me only, or to everyone? If the latter, I truly hope Apple can add the function soon back the iWork suite.

    You need to go back to Pages 4 for this to work.
    Let Apple know you want it back via
    http://www.apple.com/feedback

  • Java sockets and raw sockets

    Hello!
    I have made my own file sharing program with Java sockets
    and i have read a litle bit about raw sockets also.
    What are the differences between Java sockets and raw sockets?

    raw socket can have packet types which Java does not.
    Generally if you need something useful which Java cannot do there is a utility already written which does what you want, e.g. ping and you can call that.

Maybe you are looking for

  • Audio out of Sync - Final Cut Pro to Soundtrack and back

    I have edited some talking head interviews in FCP 7.0.3 When I "Send to Soundtrack Pro Multitrack Project" and then send back to Final Cut (by exporting an AIFF) The audio is 9 frames shorter than the original audio. (The video is 06:29:12 long) I ha

  • Servlets

    how servlets communicate with each other? and how applet to servlet communication is achieved?

  • Payroll log

    Hi, In payroll log /ZEA - BF ESI basis, i m getting the wrong amount. How to solve this one. Pls let me know. Thanks and Regards, Revathi.

  • 30 second rewind there on some books, missing on others. How can I activate it for all books?

    Greetings all. I listen to a lot of audiobooks while I drive. Many of my audiobooks have the 30 second rewind feature, while some don't. I love the feature and use it frequently. I have tried to figure out a correlation between various Option setting

  • FM for reading longtext of a bp ?

    Hello experts, I need a  function modul in order to read the longtext of a bp for example like marketing note or correspondence. Hope someone can help me , thanks, Gerd