Concurrent Sockets using NIO

I am creating a server using the 1.4x jre and NIO everytime I run the server process I max out at 64 concurrent connections. Spawning a new thread does not seem to work. I know other people have conquered this hurdle and I would appreciate any guidance I could get. Thanks in advance.

I have my environment set up so I can compile and run test programs (when I want ) using beta 1.4.02. This does not seem to solve the problem. The error is caused when after 64 connections have been accepted and you loop back to selector.select().
The error message is slightly different depending on which tester I am running but it boils down to
java.io.IOException: The parameter is incorrect
     at sun.nio.ch.PollArrayWrapper.poll0(Native Method)
     at sun.nio.ch.PollArrayWrapper.poll(PollArrayWrapper.java:146)
     at sun.nio.ch.PollSelectorImpl.doSelect(PollSelectorImpl.java:46)
     at sun.nio.ch.SelectorImpl.select(SelectorImpl.java:62)
     at sun.nio.ch.SelectorImpl.select(SelectorImpl.java:67)
     at mindbridge.test.Server4.run(Server4.java:79)
     at java.lang.Thread.run(Thread.java:536)

Similar Messages

  • Sockets using NIO

    Hi all,
    I have a design question regarding socket architecture.
    I have written a server where there are certain services running. this is actually a socket server.
    Now i am writing a client.
    The challenge is the clients are many applets in one jsp page and all of them will essentially use one connection that is established to the server.
    So either we can make a basic applet which all others applets extend and use it.
    Can someone help with the code in java socket/nio to use and implement this kind of architecture?

    If the server uses NIO, there is not requirement for the client to do the same.
    Sharing code does not mean they will share the same connection, only that they will do it the same way. I would suggest you get it to work with individual connections and then optimise it to use a single connection.

  • Error when trying to write to a socket using nio

    Hi,
    I am getting this error when trying to write using the new io
    The system detected an invalid pointer address in attempting to use a pointer argument in a call
    can anyone tell me what's wrong ?

    Please post the whole Exception.printStackTrace report. Also a small example that reproduces the problem.

  • Reading Objects using NIO

    I having problems reading an object using NIO APIs. I am end creating an Object and pass it through a socket. When I retrieve the data from the input stream within the socket I initialize a ByteBuffer by allocating a length. The problem is that there is NO way of knowing what to allocate that ByteBuffer when reading in the object. Below is within a method that allows me to read information from the socket.
    //Allocate the length ByteBuffer.
    ByteBuffer buffer = ByteBuffer.allocate(1024);
    //Read the data from the SocketChannel....PROBLEM IS WHAT IF I NEED TO DO MULTIPLE READS
    socketChannel.read(buffer);
    ///We will create a byte array from the ByteBuffer.
    byte[] b = buffer.array();
    //ByteArrayInputStream that we will create and put the byte array in.
    ByteArrayInputStream bis = new ByteArrayInputStream(b);
    //ObjectInputStream where we will use the ByteArrayInputStream.
    ObjectInputStream input = new ObjectInputStream(bis);
    //Object that we will read in.
    Object obj = input.readObject();
    //Message that we will end up receiving.     
    Message receivingMsg = null;
    //Once we have our Message we will end up closing the connection.
    bis.close();
    input.close();
    //We will clear the buffer.
    buffer.clear();
    //We will cast the object to a message object so
    //that we can end up sending it through the right
    //routine which will allow us to send a response
    //back to the client. *********SPECIAL Class that will cast our generic object into a Message Object.
    Message receivedFromClient = (Message) obj;
    //we will end up taking that message and returning it.
    Message returningMsg = communicate(receivedFromClient);
    //Here we will end up taking the Message and putting it into the ByteBuffer.          
    ByteBuffer bb = objectToOutputStreamByteBuffer(returningMsg);
    socketChannel.write(bb);
    ----The problem is if I have more data within that Object. I need to re-allocate the ByteBuffer object and read everything on that socket. I tried the following code but I really don't feel it will be optimized the best for performance. I guess my question is that should I even be using NIO in this situation or Blocking IO?
    Again, here is the code that will read multiple data from the socket until it is -1.
    //Here we will read the information we received by first allocating
    //a ByteBuffer object.
    ByteBuffer buffer1 = ByteBuffer.allocate(5);
    ByteBuffer buffer2 = ByteBuffer.allocate(0);
    //We will read the data from this object.
    while ((socketChannel.read(buffer1)) != -1) {
    //We will check the Buffers and then try to recreate a new ByteBuffer that will put the remaining
    //stuff within the buffer. NOT SURE IF THIS IS THE MOST EFFICIENT WAY OF DOING THIS
    //AND ACTUALLY DON'T HAVE THE CODE WORKING CORRECTLY. THIS IS WHERE I
    //NEED HELP ON THE CORRECT WAY TO DO THIS.
         if (buffer1.remaining() < buffer2.remaining()) {
              buffer1.flip();
              buffer2 = ByteBuffer.allocate(buffer1.remaining() + buffer2.remaining());
              System.out.println("tmp 2 Remaining : " + buffer2.remaining());
              //tmp.put(buffer2);
              //buffer2 = tmp;
              System.out.println("Buffer 2 Remaining : " + buffer2.remaining());
         buffer2.put(buffer1);
         buffer1.clear();
    //We will create a byte array from the ByteBuffer.                    
    byte[] b = buffer.array();
    //ByteArrayInputStream that we will create and put the byte array in.
    ByteArrayInputStream bis = new ByteArrayInputStream(b);
    //ObjectInputStream where we will use the ByteArrayInputStream.
    ObjectInputStream input = new ObjectInputStream(bis);
    //Object that we will read in.
    Object obj = input.readObject();
    //Message that we will end up receiving.     
    Message receivingMsg = null;
    //Once we have our Message we will end up closing the connection.
    bis.close();
    input.close();
    //We will clear the buffer.
    buffer2.clear();
    buffer1.clear();
    //We will cast the object to a message object so
    //that we can end up sending it through the right
    //routine which will allow us to send a response
    //back to the client.
    Message receivedFromClient = (Message) obj;
    //we will end up taking that message and returning it.
    Message returningMsg = communicate(receivedFromClient);
    //Here we will end up taking the Message and putting it into the ByteBuffer.          
    ByteBuffer bb = objectToOutputStreamByteBuffer(returningMsg);
    socketChannel.write(bb);
    Any help would be greatly appreciated.

    I use my own InputStream class overriding the two standard read functions read( byte[], index, length ) and read(). When you construct it pass in the channel you are reading from and read from the channel on demand. ie when a call to read comes in you read say 100 bytes from the channel. The call required only 80 so these are consumed and the other 20 are buffered. Another read call is made, this time for 50 bytes but we only have 20 buffered so another read of the channel is needed. It is up to you whether you break the contract of read( byte[], index, length ) to keep reading the channel until the full "length" is available, or handle this in your application code.
    Then because this class is InputStream you can wrap it up inside any stream you like such as the ObjectInputStream and the data will be serialized correctly.

  • 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.

  • Summary : WF: PO - Emailing PO's from concurrent program using new workflow

    Hi Consultants,
    We have requirement to send PO - Emailing PO's from concurrent program using new workflow
    Request details>
    develop a way to email a PO as a PDF from the reports menu. Currently the PO can only be emailed from the PO approval screen.
    The business would like a way to email the PO anytime after the PO is approved. Reference IT Request ticket #87341.
    Ticket#87341: Details
    Details: If a purchase order has been sent to the supplier by email, and it needs to be resent for some reason (lost, recipient out on vacation, etc.)
    we have to print off a hard copy, then scan it and email it out.
    We cannot just send a new email copy directly. We would like to have the ability to re-send an email copy of the PO directly.
    Business Justification: If a purchase order has been sent to the supplier by email, and it needs to be re-sent for some reason (lost, recipient out on vacation, etc.) we have to print off a hard copy, then scan it and email it out. We cannot just send a new email copy directly.
    This takes extra time and is inefficient.
    Please advice me how can i achive this one
    Thanks,
    Ashok

    Pl post details of OS, database and EBS versions.
    Pl see if MOS Doc 387949.1 (How Can a User Email a Purchase Order To an Email Address Without Modifying and Reapproving the PO?) can help
    HTH
    Srini

  • How to write a (g)zip file to disk using NIO

    Hi,
    I want to write some data to a zipped file. I have all data to write to disk in ByteBuffer objects so I want to use NIO. The GZIPOutputstream does not have a getChannel() method. So what is the best method to zip data to file?
    Any comments are welcome!!
    Uli

    Sorry, wrong ByteBuffer in my claspath.
    So why don't you copy the bytes out of it using the get(byte[], int, int) ?

  • Running report in concurrent manager using unix shell script to create PDF

    Hi,
    I need help urgently, we are in the process of migrating from 10.7 to 11i. My problem is we have a report created in 10.7 that is ran through concurrent manager using shell scripts(host) and the output is stored as .pdf, in 10.7, it works perfectly. Now I am also doing it in 11i but it gives some error. The shell script from 10.7 is: r25runm module=$XXX_TOP/srw/test.rdf \
    userid=$1 batch=yes \
    desformat=pdf destype=file \
    desname=$XXX_TOP/outbound/test.pdf
    I change the shell script in 11i as follows:
    ar60runb report=$XXX_TOP/reports/US/test.rdf \
    userid=$1 batch=yes \
    desformat=pdf destype=file \
    desname=$XXX_TOP/outbound/test.pdf
    I checked your metalink, and I am confused which is the right executable I should use, is it ar60runb or ar60run or rwrun60b or rwrun60c or rwrun60b, which is which? how many parameters do I have to include?, some documents are saying I have to use the 4 parameters-orauser/pwd, userid,username, request_id, others one.Which parameter/s go/es with what executable. We are using HP-UX server 64 bit. In 11i, when I run in concurrent manager it gives me an error:The executable file /chdev/fd11/u00/fd11appl/xxx/1.0/bin/test for this concurrent program cannot be executed.
    Contact your system administrator or support representative. Verify that the execution path to the executable file is co.
    I have checked Metalink and follow the directions, created a link fndcpesr, check and set the permissions, etc. Play around with the executables ar60runb or rwrun60 etc., the parameters. The ar60* or rwrun60* executable permissions are -rwxr-xr-x and $XXX_TOP/fnd/../fndcpesr is -rwxr-xr-x. Also, why is ar60* executables located in $FND_TOP/bin, whereas rwrun60* executables are in $ORACLE_HOME/bin? Please help, I need an answer urgently ,I have to complete this task before Tuesday 9/16/2003 for our migration deadline. Thank you very much.

    I have already fixed the problem, TY anyway

  • Anyone use nio-memory-manager ?? what's it good for?

    Can someone give me an example of when the nio-memory-manager should be used?
    Thanks,
    Andrew

    If I remember the outcome of my experiments with NIO right the situation is as follows:
    1. Allocating/releasing huge shared memory blocks over and over can lead to OS/JVM issues. To avoid this I allocated the max size I wanted from the start (this is an option when configuring "off-heap" storage I believe). When doing it this way I had no reliability issues with the NIO memory manager in my tests.
    2. Tangosol/Oracle used to claim that the off-heap (NIO memory manager) result in worse performance than on-heap - I could not see any clear indication of this but this may be application dependent. For our app the reduced number of JVM:s per server (reducing network communication, number of threads, risk of any JVM performing GC at a given time etc etc) seemed to more than offset the allegedly slower memory manager resulting in MUCH BETTER performance! A lot of queries etc anyhow (at least for us) mainly work against indexes that always are stored "on-heap"...
    3. There is a limitation to 2Gb per NIO block (at least in 32-bit JVM:s not sure about 64:bit - never seen any point in using them since larger heaps than 2Gb seldom work well anyhow and each pointer consumes double the space in heap and CPU-caches) but this is for each CACHE and separate for PRIMARY and BACKUP I believe! So my understanding is that if you (using 64-bit OS) for instance have two (equally big) caches you could allocate max 2 * 2 * 2 = 8Gb of off-heap memory for folding data per JVM (without ANY impact on GC-pauses!) and in addition to that use as much heap as you can get away with (given GC-pause times) for holding the indexes to that data. This would makes a huge difference in JVM count!- for example we today have to run like 10+ JVM:s per server using "on-heap" while we using "off-heap" storage probably could get that down to one or two JVM:s per server!
    4. There may be both OS and JVM parameter that you need to set (depending on OS and JVM used!) in order to allocate large amounts of shared memory using NIO (the default is rather small).
    As for the question about de-allocation I never saw any sign of memory leaks with the NIO memory manager (i.e. space previously occupied by deleted objects were reused for new objects) but as I mentioned above you better allocating the max size NIO memory block you intend to use up-front and that memory will then remain allocated for this use so if your amount of cache data vary and you would like to use memory for other purposes (like heap!) at some point you may be better of sticking with "on-heap" that is more flexible in that respect.
    As I previously mentioned off-heap is today (until Oracle fixes the improvement request!) really only an option if you do not plan to use "overflow protection" or your objects are fixed size :-(
    And if you are interested in using servers with a lot of memory and would like to use "off-heap" please talk to your Oracle sales rep about it! If enough people do that it may allow the Coherence developers to assign more time for making "off-heap" storage better! With this feature in place Coherence will be even more of a "killer application" than it already is!
    Best Regards
    Magnus

  • Can I load batteries from an electrical socket, using the same as my IPhone charger?

    Can I load batteries from an electrical socket, using the same as my IPhone charger?

    Your terminology is confusing...  If you are describing the USB power adapter (that plugs into a wall outlet) that you use to charge your iPhone, you can use the same connection to charge your iPod nano.

  • GZIP using nio ByteBuffer

    In Java 1.4 CharsetEncoder/CharsetDecoder classes were added to encode/decode unicode to/from ByteBuffers to fully utilize the performance advantages of the nio package. Why didn't they do the same for GZIP compresssion/decompression? Does anyone know of a way to read/write a GZIP file using nio and compress/decompress to/from ByteBuffers instead of using GZIPInputStream and GZIPOutputStream?

    llschumacher wrote:
    That will work but it is not what I had in mind. I wish to offload compression/decompression to another thread. Basically what I am doing is reading byte buffers with one thread, queueing them to a second thread to decompress and then queueing the decompressed buffer to a third thread for Unicode Decoding. I also want to use 3 threads in reverse order to perform writes. I can do this with Unicode encode/decode using CharsetEncoder/CharsetDecoder classes because they deal directly with ByteBuffers. Your solution would require me to use the same thread for IO and compress/decompress.here you go...
    1) create a threadpool executor.
    2) inherit from and extend callables to read or write nio channel objects
    3) use Inflate/Deflate on byte[] for your needs.
    4) works for JCE code as well

  • I plug my 1 month old iPad mini retina into a uk plug socket using the out of the box charger, it charged from 0-27% in 3 hours and now refuses to charge at all. Any ideas are more than welcome!!!

    I plugged my iPad Mini Retina in to charge this morning in a UK plug socket using the official out of the box charger.
    It charged from 0-27% in roughly 3 hours.
    I have come home to find it is not charging at all, when turned off when I plug the powered cable in it does turn on as if it is receiving power but it does not charge.
    It is 1 month old and hasn't experienced heavy usage as such.

    Thanks Sig. The information is here: Anything useful stand out?
    Battery Information:
      Model Information:
      Serial Number:    9G1130CJVD3MA
      Manufacturer:    DP
      Device Name:    bq20z451
      Pack Lot Code:    0000
      PCB Lot Code:    0000
      Firmware Version:    0201
      Hardware Revision:    0002
      Cell Revision:    0158
      Charge Information:
      Charge Remaining (mAh):    5663
      Fully Charged:    Yes
      Charging:    No
      Full Charge Capacity (mAh):    5663
      Health Information:
      Cycle Count:    59
      Condition:    Normal
      Battery Installed:    Yes
      Amperage (mA):    261
      Voltage (mV):    12574
    System Power Settings:
      AC Power:
      System Sleep Timer (Minutes):    10
      Disk Sleep Timer (Minutes):    10
      Display Sleep Timer (Minutes):    10
      Wake on AC Change:    No
      Wake on Clamshell Open:    Yes
      Wake on LAN:    Yes
      Current Power Source:    Yes
      Display Sleep Uses Dim:    Yes
      Battery Power:
      System Sleep Timer (Minutes):    10
      Disk Sleep Timer (Minutes):    10
      Display Sleep Timer (Minutes):    2
      Wake on AC Change:    No
      Wake on Clamshell Open:    Yes
      Display Sleep Uses Dim:    Yes
      Reduce Brightness:    Yes
    Hardware Configuration:
      UPS Installed:    No
    AC Charger Information:
      Connected:    Yes
      ID:    0x0100
      Wattage (W):    60
      Revision:    0x0000
      Family:    0x00ba
      Serial Number:    0x00262704
      Charging:    No

  • Why can't GB let me use 'electric guitar' option when using Nio 2/4 interface - I have to use real instrument and miss out on all the effects. Is this normal for all interfaces?

    Why can't GB let me use 'electric guitar' option when using Nio 2/4 interface - I have to use real instrument and miss out on all the effects. Is this normal for all interfaces? The Nio reads hte guitar but GB doesn't....

    Usually effects packages are AU plugins that would have no effect on track selection. Interfaces should have no control over what kind of track you can select. I really think something else is going on her maybe something you overlooked.
    Did you choose the input channel in the track info pane. Try both channel 1 mono or channel 2 mono. Make sure the track is record enabled.

  • Pls, Determine what file's encoding when read a file use NIO

    Hi every body,
    When I use NIO (New I/O JDK1.4) to read a file's content.
    How can I know exactly file's encoding (example: UTF-8, Cp1252, shift-jis ...) to choose right decoder to decode the file??
    Thanks
    Best regards.
    Hung, Nguyen Thanh.

    I think there's no way to do that except...
    If you are sure your files are all in japanese,
    you can use JISAutoDetect encoding.

  • Is is possible to create Socket using Java Stored Procedures/Function(Ora)?

    Hello Friends,
    Is is possible to create Socket using Java Stored Procedures/Function in Oracle?
    OR
    How I can send a message from oracle to Java Desktop Application which is working like server program?
    Please Guide !!

    J3Ganesh wrote:
    Hello Friends,
    Is is possible to create Socket using Java Stored Procedures/Function in Oracle?No, Oracle was very careful to take that feature out of the JDK provided in Oracle 10/11, but you can buy that feature back for, if I remember correctly, about 5000 dollars. (I actually raised a service request on this and then told my rep what I thought about the answer I received--some thing along the line of money grubbing so and so....)
    How I can send a message from oracle to Java Desktop Application which is working like server program?You can make a table and poll it from time to time from the Java side and write and commit what ever you want to the table. I do not know any way to send a signal from Oracle DB an external Java application--Java or PL/SQL stored procedure.

Maybe you are looking for

  • Error on Checking/Unchecking "Show"

    I an a designer getting ready to train my client in Contribute CS3. I have considerable experience with optional editable areas in DW templates and training clients in how to make items visible and not visible. However, in my current website I receiv

  • Report on Vendor Ontime Delivery

    Hi Is there any Standard SAP report available on Vendor Ontime delivery, which is report showing deviation of PO delivery Date and GR date we need this report to monitor vendors Thanks

  • DVD Drive problem

    Is it just me or are people having a lot of problems with there DVD Drives. I had mine replaced back in April, barely used the drive, went to use it tonight and its ejecting discs again. Surely it can't be gone again. Can anyone give me any ideas at

  • Exposing REST service as EJB 3.1 method

    How to convert Restful WebService (RestEasy) to EJB 3.1 Stateless session bean In my current project we are using Restful Web Services (Resteasy) combined with Jpos and Jcard with an ISO-8583 message format. The task is to remove all the dependencies

  • Just got a ipod touch 4th gen yesterday and didnt get charger is there anyway i can get one for free?

    any help on getting a free ipod touch 4th gen charger?