Asynchronous sockets in solaris

Hi, I don't know if the message fits the forum. But I didn't find any better. My question is what is the best way to program asynchronous socket I/O to get maximum performance . (System calls, programming method,...).
In winnt we had IoCompletionPort. What does SOLARIS offer??

Suresh,
You will find very good information on docs.sun.com site on
solaris sockets.
And specifically, http://docs.sun.com/?q=sockets&p=/doc/806-4125/6jd7pe6b6&a=view
It has basic info on solaris sockets.
Hope this helps.
Thx
Tushar Patel.

Similar Messages

  • Wierdness with NIO socket on Solaris 2.10 part I

    i tried the following NioClient and MockServer, and saw some weird behavior.
    1. If i run both the client and server on the same machine on Windows, the client connects to the server, queries the instrument and gets the list of instruments back.
    2. if i run both client and server on the same Solaris 2.10 box, the NioClient doesn't get anything back from the MockServer, not even an ACCEPT
    3. if i run the client and the server on different solaris 2.10 machines, they work fine.
    have anyone seen this before? can sometone sheds some lights?
    import java.net.*;
    import java.io.*;
    public class MockServer
         public static int counter = 2;
        public static void main(String[] args) throws IOException {
             int portNumber = Integer.parseInt(args[0]);
            ServerSocket serverSocket = null;
            try {
                serverSocket = new ServerSocket(portNumber);
            } catch (IOException e) {
                System.err.println("Could not listen on port: " + portNumber);
                System.exit(1);
             System.out.println ("Listening on socket " + portNumber);
            do {             
                 Socket clientSocket = null;
                 try {
                     clientSocket = serverSocket.accept();
                     System.out.println ("starting a new client....");
                     MyThread mt = new MyThread (clientSocket);
                     mt.run ();
                 } catch (IOException e) {
                     System.err.println("Accept failed.");
                     System.exit(1);
            while (true);
    class MyThread
         private final Socket clientSocket;
         MyThread (Socket clientSocket)
              this.clientSocket = clientSocket;
         public void run ()
            new Thread (new Runnable () {
                     public void run ()
                          try
                               boolean instrumentquery = false;
                               PrintWriter out = new PrintWriter(clientSocket.getOutputStream(), true);
                               BufferedReader in = new BufferedReader(
                                           new InputStreamReader(
                                           clientSocket.getInputStream()));
                               String inputLine;                          
                               String successoutputLine =
                                    "<?xml version=\"1.0\" encoding=\"UTF-8\"?><return><returncode>success</returncode><detail>everything is good</detail></return>";
                               String failoutputLine =
                                    "<?xml version=\"1.0\" encoding=\"UTF-8\"?><return><returncode>failure</returncode><detail>something is not good</detail></return>";
                               String instrumentsoutput =
                                    "<?xml version=\"1.0\" encoding=\"UTF-8\"?><instruments><instrument><contract>usg-505Y</contract><cusip>12131121</cusip><deactivated>false</deactivated><halted>false</halted></instrument><instrument><contract>usg-305Y</contract><cusip>121312342</cusip><deactivated>false</deactivated><halted>false</halted></instrument></instruments>";
                               while ((inputLine = in.readLine()) != null) {
                                    System.out.println ("Receiving the following" + inputLine);
                                    if (inputLine.contains("queryInstrument")) instrumentquery = true;
                                    if (inputLine.contains("</a>"))
                                         if (instrumentquery)
                                              instrumentquery = false;
                                              System.out.println ("Sending " + instrumentsoutput);
                                              out.println (instrumentsoutput);
                                         else
                                              if ((MockServer.counter % 2) == 0)
                                                   System.out.println ("Sending " + successoutputLine);
                                                   out.println(successoutputLine);
                                              else
                                                   System.out.println ("Sending " + failoutputLine);
                                                   out.println(failoutputLine);
                                              MockServer.counter++;
                               out.close();
                               in.close();
                               clientSocket.close();}
                          catch (Exception ex)
                 }).start (); }
    }please see topic "wierdness with NIO socket on Solaris 2.10 part II" for the NioClient code as the maximum per topic is 5000.

    code for NioClient.java
    import java.io.IOException;
    import java.net.InetAddress;
    import java.net.InetSocketAddress;
    import java.net.Socket;
    import java.nio.ByteBuffer;
    import java.nio.channels.SelectionKey;
    import java.nio.channels.Selector;
    import java.nio.channels.SocketChannel;
    import java.nio.channels.spi.SelectorProvider;
    import java.util.*;
    public class NioClient implements Runnable {
    private InetAddress hostAddress;
    private int port;
    private Selector selector;
    private ByteBuffer readBuffer = ByteBuffer.allocate(8192);
    private List pendingChanges = new LinkedList();
    private Map pendingData = new HashMap();
    private Map rspHandlers = Collections.synchronizedMap(new HashMap());
    public NioClient(InetAddress hostAddress, int port) throws IOException {
    this.hostAddress = hostAddress;
    this.port = port;
    this.selector = this.initSelector();
    public void send(byte[] data, RspHandler handler) throws IOException {
    SocketChannel socket = this.initiateConnection();
    this.rspHandlers.put(socket, handler);
    synchronized (this.pendingData) {
    List queue = (List) this.pendingData.get(socket);
    if (queue == null) {
    queue = new ArrayList();
    this.pendingData.put(socket, queue);
    queue.add(ByteBuffer.wrap(data));
    this.selector.wakeup();
    public void run() {
    while (true) {
    try {
    synchronized (this.pendingChanges) {
    Iterator changes = this.pendingChanges.iterator();
    while (changes.hasNext()) {
    ChangeRequest change = (ChangeRequest) changes.next();
    switch (change.type) {
    case ChangeRequest.CHANGEOPS:
    SelectionKey key = change.socket
    .keyFor(this.selector);
    key.interestOps(change.ops);
    break;
    case ChangeRequest.REGISTER:
    change.socket.register(this.selector, change.ops);
    break;
    this.pendingChanges.clear();
    this.selector.select();
    Iterator selectedKeys = this.selector.selectedKeys().iterator();
    while (selectedKeys.hasNext()) {
    SelectionKey key = (SelectionKey) selectedKeys.next();
    selectedKeys.remove();
    if (!key.isValid()) {
    continue;
    if (key.isConnectable()) {
    this.finishConnection(key);
    } else if (key.isReadable()) {
    this.read(key);
    } else if (key.isWritable()) {
    this.write(key);
    } catch (Exception e) {
    e.printStackTrace();
    private void read(SelectionKey key) throws IOException {
    SocketChannel socketChannel = (SocketChannel) key.channel();
    this.readBuffer.clear();
    int numRead;
    try {
    numRead = socketChannel.read(this.readBuffer);
    } catch (IOException e) {
    key.cancel();
    socketChannel.close();
    return;
    if (numRead == -1) {
    key.channel().close();
    key.cancel();
    return;
    this.handleResponse(socketChannel, this.readBuffer.array(), numRead);
    private void handleResponse(SocketChannel socketChannel, byte[] data,
    int numRead) throws IOException {
    byte[] rspData = new byte[numRead];
    System.arraycopy(data, 0, rspData, 0, numRead);
    RspHandler handler = (RspHandler) this.rspHandlers.get(socketChannel);
    if (handler.handleResponse(rspData)) {
    socketChannel.close();
    socketChannel.keyFor(this.selector).cancel();
    private void write(SelectionKey key) throws IOException {
    SocketChannel socketChannel = (SocketChannel) key.channel();
    synchronized (this.pendingData) {
    List queue = (List) this.pendingData.get(socketChannel);
    while (!queue.isEmpty()) {
    ByteBuffer buf = (ByteBuffer) queue.get(0);
    socketChannel.write(buf);
    if (buf.remaining() > 0) {
    break;
    queue.remove(0);
    if (queue.isEmpty()) {
    key.interestOps(SelectionKey.OP_READ);
    private void finishConnection(SelectionKey key) throws IOException {
    SocketChannel socketChannel = (SocketChannel) key.channel();
    try {
    socketChannel.finishConnect();
    } catch (IOException e) {
    System.out.println(e);
    key.cancel();
    return;
    key.interestOps(SelectionKey.OP_WRITE);
    private SocketChannel initiateConnection() throws IOException {
    SocketChannel socketChannel = SocketChannel.open();
    socketChannel.configureBlocking(false);
    socketChannel
    .connect(new InetSocketAddress(this.hostAddress, this.port));
    synchronized (this.pendingChanges) {
    this.pendingChanges.add(new ChangeRequest(socketChannel,
    ChangeRequest.REGISTER, SelectionKey.OP_CONNECT));
    return socketChannel;
    private Selector initSelector() throws IOException {
    return SelectorProvider.provider().openSelector();
    public static void main(String[] args) {
    try {
    System.out.println ("the host name is " + args[0]);
    NioClient client = new NioClient(
    InetAddress.getByName(args[0]), 4444);
    Thread t = new Thread(client);
    t.setDaemon(true);
    t.start();
    RspHandler handler = new RspHandler();
    client.send(
    "<?xml version=\"1.0\" encoding=\"UTF-8\"?><a><queryInstrument/></a>\n"
    .getBytes(), handler);
    handler.waitForResponse();
    } catch (Exception e) {
    e.printStackTrace();
    }

  • Asynchronous socket programming in Java?

    I am a C++ programmer, I just wonder how do I do asynchronous programming in Java?
    In VC++, you can hook an event handler to the socket and the system will fire an event whenever there is data coming in to the socket. The event handler can then spawn a thread and handle the network message.
    In Unix, you can use the select() function. This function will return whenever the indicated socket fires events. If nothing happens within the timeout period, the function simply returns.
    What about in Java? I don't see any methods that allows you to hook an event handler to it. Is there anything like select() function in Unix?
    Thanks so much.

    There is something very much like C's select: selectors. I don't immediately know where to read more about them but google for things like "java selector example", "java nio tutorial", etc (NIO = new I/O, the library where selectors live.)
    Another way to do async sockets in Java is by threading. That is the traditional way before New I/O. It's still a perfectly good and easy way, thanks to Java's easy threading. Downside is that it scales to only maybe 100-200 simultaneous connections per server (will depend on your operating system). For thread-based sockets check Sun's Java socket tutorial (first item when you google "java socket tutorial").

  • Maximum # socket descriptors, Solaris 2.5.1?

    Hello,
    Does anyone know what is the maximum number of socket descriptors that can be opened simultaneously in one process? Where in the system do I check/set that?
    Also, what is maximum number of children a process can have and where is that setting?
    I am working with Solaris 2.5.1.
    Any help is appreciated. Thanks in advance!
    -Max

    When the keyboard is disconnected...display automatically goes to the serial port. If your keyboard is connected, reboot and make sure you have a video card installed. The onboard one may not have the vsimm(video memory) option, in which case you will have to get memory for it(very, very expensive) or get a separate sbus video card(these can be had very cheap on ebay). Let us know how it works out for you.

  • Wierdness with NIO socket on Solaris 2.10 part I I

    import java.io.IOException;
    import java.net.InetAddress;
    import java.net.InetSocketAddress;
    import java.net.Socket;
    import java.nio.ByteBuffer;
    import java.nio.channels.SelectionKey;
    import java.nio.channels.Selector;
    import java.nio.channels.SocketChannel;
    import java.nio.channels.spi.SelectorProvider;
    import java.util.*;
    public class NioClient implements Runnable {
    private InetAddress hostAddress;
    private int port;
    private Selector selector;
    private ByteBuffer readBuffer = ByteBuffer.allocate(8192);
    private List pendingChanges = new LinkedList();
    private Map pendingData = new HashMap();
    private Map rspHandlers = Collections.synchronizedMap(new HashMap());
    public NioClient(InetAddress hostAddress, int port) throws IOException {
    this.hostAddress = hostAddress;
    this.port = port;
    this.selector = this.initSelector();
    public void send(byte[] data, RspHandler handler) throws IOException {
    SocketChannel socket = this.initiateConnection();
    this.rspHandlers.put(socket, handler);
    synchronized (this.pendingData) {
    List queue = (List) this.pendingData.get(socket);
    if (queue == null) {
    queue = new ArrayList();
    this.pendingData.put(socket, queue);
    queue.add(ByteBuffer.wrap(data));
    this.selector.wakeup();
    public void run() {
    while (true) {
    try {
    synchronized (this.pendingChanges) {
    Iterator changes = this.pendingChanges.iterator();
    while (changes.hasNext()) {
    ChangeRequest change = (ChangeRequest) changes.next();
    switch (change.type) {
    case ChangeRequest.CHANGEOPS:
    SelectionKey key = change.socket
    .keyFor(this.selector);
    key.interestOps(change.ops);
    break;
    case ChangeRequest.REGISTER:
    change.socket.register(this.selector, change.ops);
    break;
    this.pendingChanges.clear();
    this.selector.select();
    Iterator selectedKeys = this.selector.selectedKeys().iterator();
    while (selectedKeys.hasNext()) {
    SelectionKey key = (SelectionKey) selectedKeys.next();
    selectedKeys.remove();
    if (!key.isValid()) {
    continue;
    if (key.isConnectable()) {
    this.finishConnection(key);
    } else if (key.isReadable()) {
    this.read(key);
    } else if (key.isWritable()) {
    this.write(key);
    } catch (Exception e) {
    e.printStackTrace();
    private void read(SelectionKey key) throws IOException {
    SocketChannel socketChannel = (SocketChannel) key.channel();
    this.readBuffer.clear();
    int numRead;
    try {
    numRead = socketChannel.read(this.readBuffer);
    } catch (IOException e) {
    key.cancel();
    socketChannel.close();
    return;
    if (numRead == -1) {
    key.channel().close();
    key.cancel();
    return;
    this.handleResponse(socketChannel, this.readBuffer.array(), numRead);
    private void handleResponse(SocketChannel socketChannel, byte[] data,
    int numRead) throws IOException {
    byte[] rspData = new byte[numRead];
    System.arraycopy(data, 0, rspData, 0, numRead);
    RspHandler handler = (RspHandler) this.rspHandlers.get(socketChannel);
    if (handler.handleResponse(rspData)) {
    socketChannel.close();
    socketChannel.keyFor(this.selector).cancel();
    private void write(SelectionKey key) throws IOException {
    SocketChannel socketChannel = (SocketChannel) key.channel();
    synchronized (this.pendingData) {
    List queue = (List) this.pendingData.get(socketChannel);
    while (!queue.isEmpty()) {
    ByteBuffer buf = (ByteBuffer) queue.get(0);
    socketChannel.write(buf);
    if (buf.remaining() > 0) {
    break;
    queue.remove(0);
    if (queue.isEmpty()) {
    key.interestOps(SelectionKey.OP_READ);
    private void finishConnection(SelectionKey key) throws IOException {
    SocketChannel socketChannel = (SocketChannel) key.channel();
    try {
    socketChannel.finishConnect();
    } catch (IOException e) {
    System.out.println(e);
    key.cancel();
    return;
    key.interestOps(SelectionKey.OP_WRITE);
    private SocketChannel initiateConnection() throws IOException {
    SocketChannel socketChannel = SocketChannel.open();
    socketChannel.configureBlocking(false);
    socketChannel
    .connect(new InetSocketAddress(this.hostAddress, this.port));
    synchronized (this.pendingChanges) {
    this.pendingChanges.add(new ChangeRequest(socketChannel,
    ChangeRequest.REGISTER, SelectionKey.OP_CONNECT));
    return socketChannel;
    private Selector initSelector() throws IOException {
    return SelectorProvider.provider().openSelector();
    public static void main(String[] args) {
    try {
    System.out.println ("the host name is " + args[0]);
    NioClient client = new NioClient(
    InetAddress.getByName(args[0]), 4444);
    Thread t = new Thread(client);
    t.setDaemon(true);
    t.start();
    RspHandler handler = new RspHandler();
    client.send(
    "<?xml version=\"1.0\" encoding=\"UTF-8\"?><a><queryInstrument/></a>\n"
    .getBytes(), handler);
    handler.waitForResponse();
    } catch (Exception e) {
    e.printStackTrace();
    }Edited by: LuriRon on Mar 16, 2009 10:42 AM

    import java.io.IOException;
    import java.net.InetAddress;
    import java.net.InetSocketAddress;
    import java.net.Socket;
    import java.nio.ByteBuffer;
    import java.nio.channels.SelectionKey;
    import java.nio.channels.Selector;
    import java.nio.channels.SocketChannel;
    import java.nio.channels.spi.SelectorProvider;
    import java.util.*;
    public class NioClient implements Runnable {
    private InetAddress hostAddress;
    private int port;
    private Selector selector;
    private ByteBuffer readBuffer = ByteBuffer.allocate(8192);
    private List pendingChanges = new LinkedList();
    private Map pendingData = new HashMap();
    private Map rspHandlers = Collections.synchronizedMap(new HashMap());
    public NioClient(InetAddress hostAddress, int port) throws IOException {
    this.hostAddress = hostAddress;
    this.port = port;
    this.selector = this.initSelector();
    public void send(byte[] data, RspHandler handler) throws IOException {
    SocketChannel socket = this.initiateConnection();
    this.rspHandlers.put(socket, handler);
    synchronized (this.pendingData) {
    List queue = (List) this.pendingData.get(socket);
    if (queue == null) {
    queue = new ArrayList();
    this.pendingData.put(socket, queue);
    queue.add(ByteBuffer.wrap(data));
    this.selector.wakeup();
    public void run() {
    while (true) {
    try {
    synchronized (this.pendingChanges) {
    Iterator changes = this.pendingChanges.iterator();
    while (changes.hasNext()) {
    ChangeRequest change = (ChangeRequest) changes.next();
    switch (change.type) {
    case ChangeRequest.CHANGEOPS:
    SelectionKey key = change.socket
    .keyFor(this.selector);
    key.interestOps(change.ops);
    break;
    case ChangeRequest.REGISTER:
    change.socket.register(this.selector, change.ops);
    break;
    this.pendingChanges.clear();
    this.selector.select();
    Iterator selectedKeys = this.selector.selectedKeys().iterator();
    while (selectedKeys.hasNext()) {
    SelectionKey key = (SelectionKey) selectedKeys.next();
    selectedKeys.remove();
    if (!key.isValid()) {
    continue;
    if (key.isConnectable()) {
    this.finishConnection(key);
    } else if (key.isReadable()) {
    this.read(key);
    } else if (key.isWritable()) {
    this.write(key);
    } catch (Exception e) {
    e.printStackTrace();
    private void read(SelectionKey key) throws IOException {
    SocketChannel socketChannel = (SocketChannel) key.channel();
    this.readBuffer.clear();
    int numRead;
    try {
    numRead = socketChannel.read(this.readBuffer);
    } catch (IOException e) {
    key.cancel();
    socketChannel.close();
    return;
    if (numRead == -1) {
    key.channel().close();
    key.cancel();
    return;
    this.handleResponse(socketChannel, this.readBuffer.array(), numRead);
    private void handleResponse(SocketChannel socketChannel, byte[] data,
    int numRead) throws IOException {
    byte[] rspData = new byte[numRead];
    System.arraycopy(data, 0, rspData, 0, numRead);
    RspHandler handler = (RspHandler) this.rspHandlers.get(socketChannel);
    if (handler.handleResponse(rspData)) {
    socketChannel.close();
    socketChannel.keyFor(this.selector).cancel();
    private void write(SelectionKey key) throws IOException {
    SocketChannel socketChannel = (SocketChannel) key.channel();
    synchronized (this.pendingData) {
    List queue = (List) this.pendingData.get(socketChannel);
    while (!queue.isEmpty()) {
    ByteBuffer buf = (ByteBuffer) queue.get(0);
    socketChannel.write(buf);
    if (buf.remaining() > 0) {
    break;
    queue.remove(0);
    if (queue.isEmpty()) {
    key.interestOps(SelectionKey.OP_READ);
    private void finishConnection(SelectionKey key) throws IOException {
    SocketChannel socketChannel = (SocketChannel) key.channel();
    try {
    socketChannel.finishConnect();
    } catch (IOException e) {
    System.out.println(e);
    key.cancel();
    return;
    key.interestOps(SelectionKey.OP_WRITE);
    private SocketChannel initiateConnection() throws IOException {
    SocketChannel socketChannel = SocketChannel.open();
    socketChannel.configureBlocking(false);
    socketChannel
    .connect(new InetSocketAddress(this.hostAddress, this.port));
    synchronized (this.pendingChanges) {
    this.pendingChanges.add(new ChangeRequest(socketChannel,
    ChangeRequest.REGISTER, SelectionKey.OP_CONNECT));
    return socketChannel;
    private Selector initSelector() throws IOException {
    return SelectorProvider.provider().openSelector();
    public static void main(String[] args) {
    try {
    System.out.println ("the host name is " + args[0]);
    NioClient client = new NioClient(
    InetAddress.getByName(args[0]), 4444);
    Thread t = new Thread(client);
    t.setDaemon(true);
    t.start();
    RspHandler handler = new RspHandler();
    client.send(
    "<?xml version=\"1.0\" encoding=\"UTF-8\"?><a><queryInstrument/></a>\n"
    .getBytes(), handler);
    handler.waitForResponse();
    } catch (Exception e) {
    e.printStackTrace();
    }Edited by: LuriRon on Mar 16, 2009 10:42 AM

  • ICMP socket in solaris 9

    Hi
    i'm trying to create an alternative ping command for my application in order to not need to make a system calll to run a ping.
    after creating this ping routine, I tryed to test in solaris 10 and found an permission denied error. After looking for some explanation, I found a way to enable icmp privileges with the command
    usermod -K defaultpriv=basic,net_icmpaccess user
    but I can't find any way to enable this privilege under solaris 9, because the syntax is quite different, and I always get errors when trying.
    can anyone help me?
    best regards.
    Ilde.

    There is a lot to be taken into consideration before desiding on your backup strategy, but if you're a little confused with different options (ufs snaps, jumpstart, good old ufsdump, etc.), the choice is still simple -- ufsdump/ufsrestore are the tools you would use to perform regular backups. UFS snapshots can not be considered a reliable backup, since it depends on the reliability of the filesystem -- you loose the filesystem, you loose the snapshot and therefore to be a true backup it still needs to be backed up to an external source. I would not call flash archives and jumpstart a real backup either, since the real purpose of either is to have easy deployable system images to maintain a large number of systems. I'm sure it is possible to concoct a backup system relying on flash archives or jumpstart, but it would be quite combersome compared to true backup solutions. If you're looking for a free backup solution on Solaris, a way to go would be either ufsdump/ufsrestore or possibly open-source Amanda backup suite if you have a more complicated setup with tape loaders.

  • Broken Pipe with Non-blocking Socket

    Hello,
    I write a Unix Agent who connect on a Windows Server with socket...
    Working well on Linux but on Solaris my problem is:
    -When my agent is running before server at connection all seems OK: Connect, Select and Getsockopt but when I try to send data I have always EPIPE Signal but I can receive datas from server !
    - When my agent is strarting after the server all it's Ok
    I don't unserstand this appears on Solaris SPARC 8 and Solaris 9 Intel ...
    Please Help is there something special with non-blocking sockets on Solaris ?
    Thanks

    Can't help you much but what I would recommend is that you
    insure that your pipes are opened for both read/write, even
    though you are only going to read or write from it. This insures
    that the pipe does not close down when you hit EOF.

  • Panic with Raw Socket-Page fault in module "ip" due to a NULL pointer deref

    I see a panic when using raw sockets with Solaris 10 10/09 (u8). I included a sample program that can cause this issue (panic happens when a udp datagram is received on port 60000). This sample code works as expected with the previous version I was using - 5/08. If I bind with a port number of 0 I don't see the panic but I don't receive anything either.
    I believe I have all the latest patches installed. I'd appreciate any assistance in resolving this. Thanks...
    ^Mpanic[cpu11]/thread=fffffe8000916c60:
    BAD TRAP: type=e (#pf Page fault) rp=fffffe80009166c0 addr=83 occurred in module "ip" due to a NULL pointer dereference
    sched:
    #pf Page fault
    Bad kernel fault at addr=0x83
    pid=0, pc=0xffffffffedf86a10, sp=0xfffffe80009167b0, eflags=0x10246
    cr0: 8005003b<pg,wp,ne,et,ts,mp,pe> cr4: 6f8<xmme,fxsr,pge,mce,pae,pse,de>
    cr2: 83 cr3: 1a345000 cr8: c
    rdi: ffffffffa7092808 rsi: ffffffffb0094e00 rdx: ffffffffa73c9d40
    rcx: 0 r8: fffffe8000916878 r9: fffffe8000916880
    rax: 0 rbx: ffffffffb0094e00 rbp: fffffe8000916800
    r10: ffffffffa7c18840 r11: ffffffffa73c9d40 r12: fffffe8000916880
    r13: ffffffff9b314000 r14: ffffffff9a70b000 r15: 0
    fsb: ffffffff80000000 gsb: ffffffff9c52d800 ds: 43
    es: 43 fs: 0 gs: 1c3
    trp: e err: 0 rip: ffffffffedf86a10
    cs: 28 rfl: 10246 rsp: fffffe80009167b0
    ss: 30
    fffffe80009165d0 unix:die+da ()
    fffffe80009166b0 unix:trap+5e6 ()
    fffffe80009166c0 unix:_cmntrap+140 ()
    fffffe8000916800 ip:ip_udp_check+b0 ()
    fffffe80009168b0 ip:ip_udp_input+15a ()
    fffffe80009169d0 ip:ip_input+c7c ()
    fffffe8000916aa0 dls:i_dls_link_rx+32e ()
    fffffe8000916af0 mac:mac_rx+71 ()
    fffffe8000916b90 bnx:bnx_recv_ring_recv+113 ()
    fffffe8000916ba0 bnx:bnx_rxpkts_intr+17 ()
    fffffe8000916bc0 bnx:bnx_intr_recv+58 ()
    fffffe8000916bf0 bnx:bnx_intr_1lvl+120 ()
    fffffe8000916c40 unix:av_dispatch_autovect+78 ()
    fffffe8000916c50 unix:intr_thread+5f ()
    EXAMPLE USED TO CAUSE ABOVE PANIC
    #include        <unistd.h>
    #include        <stdio.h>
    #include        <stdlib.h>
    #include        <sys/socket.h>
    #include        <arpa/inet.h>
    #define BUFFER_SIZE 2048
    int main(int argc, char *argv[])
            int                     i, j, sd, iosize;
            char                    *ipbuffer;
            struct sockaddr_in      saddr, daddr;
            ipbuffer = calloc( 1, BUFFER_SIZE );
            //if ( ( sd = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP) ) < 0 ) {        // Works
            if ( ( sd = socket(PF_INET, SOCK_RAW, IPPROTO_UDP) ) < 0 ) {            // Fails
                    perror("socket() error");
                    exit(-1);
            saddr.sin_family = AF_INET;
            saddr.sin_addr.s_addr = inet_addr( "0.0.0.0" );
            saddr.sin_port = htons( 60000 );
            if ( bind( sd, (struct sockaddr *) &saddr, sizeof( saddr ) ) < 0 ) {
                    perror("bind() error");
                    exit(-1);
            printf( "Awaiting inbound datagrams...\n" );
            for ( i = 1; i <= 10; i++ ) {
                    j = sizeof( daddr );
                    iosize = recvfrom( sd, ipbuffer, BUFFER_SIZE, 0, (struct sockaddr *) &daddr, &j );
                    printf( "Received %d bytes from %s\n", iosize, inet_ntoa( daddr.sin_addr ) );
            close( sd );
            return( 0 );
    }------------------------------------------------------------------

    This issue could be related. Recommend you open a call with support.
    http://bugs.opensolaris.org/bugdatabase/view_bug.do?bug_id=6882984

  • Problem reading all data from Synchronous Socket

    Hi,
    I have the task to implements an C# application which communicates with a SAP system via HTTP. My application should act as a HTTP Server to the SAP system. SAP sends documents (PDFs, Word-Docs, Tifs) through HTTP-Requests to my Server. Archive Link is SAP´s name for that HTTP interface.
    Currently I am using synchronous sockets to process the communication. So
    basically I do something like this:
            Thread th = new Thread(new ThreadStart(StartListenThreaded));
         th.Start();
    The method StartListenThread looks like this:
         private void StartListenThreaded()
                   IPAddress ipAddress = IPAddress.Parse("127.0.0.1");
                   IPEndPoint EndPoint = new IPEndPoint(ipAddress, port);
                   Socket ss = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                   ss.Bind( EndPoint);
                   ss.Listen(20);
                   try
                        while(true)
                             Console.WriteLine("rnServer is waiting for a new connection..rn");
                             Socket sock = ss.Accept();
                             Console.WriteLine("Accepted connection form:"+sock.RemoteEndPoint);
                             Connection con = new Connection(sock);
                             Thread t = new Thread(new ThreadStart(con.ProcessOneRequest));
                             t.IsBackground=true;
                             t.Priority=ThreadPriority.BelowNormal;
                             t.Start();
                   catch (System.Exception e1)
                   {  Console.WriteLine("An Exception Occurred while Listening :" +e1.ToString()); }
    As mentioned above There are mostly some Word-Documents or PDF files send as the body of a request. So I need to parse the body and write the content to a file.
    Currently I use this code to accomplish that:
         while (true)
             if(socket.Available == 0)
              break;
                n = socket.Receive(bytes);
             if(n == 0)
               break;
             wr.Write(bytes,0,n); // wr is a BinaryWriter
    Now my problem is that this loop breaks before all data is received from the socket. That means it runs into the socket.Available == 0 case and ends, but there is still data available. How did I find that out? Well during debugging the code.
    With the debugger running and when stepping through the code, obviously leaves the SAP side more time to send its data.
    When doing some Console.WriteLine() after the loop with the socket.Receive() I get results > 0. So there is still data available.
    I am not asking an SAP question here. I am aware that the problem could also be on the SAP side. However I think it is a C# issue. Has anyone experienced similar problems with sockets? Am I doing something completely wrong in handling my socket? I also don´t think that I can use Asynchronous sockets beacuse I need to process incoming requests in a determined order.
    I have also tryed to turn off Blocking mode by setting socket.Blocking = false but I found out that I cannon use that because I need NetworkStream at some point in my application and NetworkStream does not work without blocking mode.

    I have evaluated several other possibilities before starting to implement HTTP on a socket basis. I only have this choice.
    I have had a detailed look at Cassini before, but since you mentioned it in your post I looked at it more closely and I think I found a solution for my Problem.
    Cassini uses some code like the following to poll for more data in a request. I am now using this mechanism in my application and it works fine.
              private int WaitForRequestBytes()
                   int availBytes = 0;
                   try
                        Console.WriteLine("socket.Available: " + socket.Available);
                        if (socket.Available == 0)
                             // poll until there is data
                             Console.WriteLine("Polling 100ms");
                             socket.Poll(100000 /* 100ms */, SelectMode.SelectRead);
                             if (socket.Available == 0 && socket.Connected)
                                  Console.WriteLine("Polling 1sec");
                                  socket.Poll(1000000 /* 1sec */, SelectMode.SelectRead);
                                  // socket.Poll(10000000 /* 10sec */, SelectMode.SelectRead);
                        availBytes = socket.Available;
                   catch
                   return availBytes;
    So thanks for putting me in the right direction.
    Mirco

  • C# socket and java socket

    hello
    i am a java programmer,recently we got a project,that need the c# app to communicate with java app ,i select the socket as intermediate.
    i notice that java socket term is divided into " blocking" and "non-blocking",the latter come from jdk1.4, the c# socket is devided into "synchronized" and "asynchronized" and both of them are blocking,
    in my project,i have tried synchronized c# socket coorperating to blocking java socket,it works well..but when i modify the c# app to ASYNCHRONIZED socket,my system DON'T works well,i don't know why? i can't find asynchronized socket in java,.i learn that nio socket is nonblocking, is it asynchronized?
    who can tell me what's is the best solution for the socket communication between java and c#?

    yes,i have read them,but it only tell me the communication between java apps,and DON'T tell me any clue about c# socket.

  • Synchronous IO with nio

    Hello,
    I have been programming in Java for a while but today is my first shot at NIO.
    I'm implementing a custom protocol over TCP between a java server and several Java and C clients. The classical one-thread-per-client approach works with a couple of test connections, but I'm afraid it will not scale:
    - I will not have control on all clients programs
    - I don't know yet the expected traffic
    - I might introduce bugs as well in the sever program and leak sockets and threads
    Here is the code for the classical approach:
    ServerSocket server.accept()  = ...;
    Socket client = server.accept();
    Thread clientThread = new ClientThread(client);
    clientThread.start();Where ClientThread's run method deos the following:
    BufferedReader reader = new BufferedReader(new InputStreamReader(client.getInputStream()));
    while (isConnected) {
        String pdu = reader.readLine();
        storeClientInfo(pdu);
    }The key is that in order to make for a very simple protocol we designed it so that each PDU is one line of text, sent over TCP. Reading one PDU is therefiore a synchronous operation.
    In order to provision scaling to many clients, we are trying to reimplement it using NIO.
    We use a Selector to wait for requests, and once accepted, we register the Selector with the created SocketChannel (one per client).
    One single thread dequeues reads selected by the Selector, but we are still trying to read using the synchronous BufferredReader.
    When a SocketChannel has readable data, we create a Buffered reader like this:
    BufferedReader reader = new BufferedReader(new InputStreamReader(socketChannel.socket().getInputStream()));
    String pdu = reader.readLine(); //  throws IllegalBlockingModeException
    }And as you probably expect, we get an IllegalBlockingModeException when reading the line (synchronous operation) over the (asynchronous) socket.
    If my understanding is correct, the SocketChannel has to be put in non-blocking mode to be selectable by the Selector (otherwise the register(...) call throws an IllegalBlockingStateException), but it cannot be read synchronously in this non-blocking mode.
    Is there any way I can connect a BufferedReader to a non-blocking SocketChannel somehow?
    There would be an alternative approach, where the listeing thread reads the data from the SocketChannel into a ByteBuffer, then stuffs those bytes into a PipedOutputStream, and build a reader over a PipedInputStream.
    The problem is that in this case, we need, again, one thread per client to read the data froml the reader...
    There's a third approach, where we would use the "attachment" feature of SocketChannel.register() and SelectedKey; in this approach, the attachment could be a stringBuffer; each time the Selector warns us that data is readable, the data would be read from the SocketChannel into a ByteBuffer. then added to the StringBuffer. We would have to analyze the StringBuffer's content to find out whether it contains a whole line, and only then extract this line as the "PDU".
    Is this a recommended approach?
    Thanks in advance, and regards,
    J.
    Message was edited by: jduprez (some code markers had been swallowed)
    Message was edited by:
    jduprez

    OK, thanks.
    I implemented this third approach, and it works under moderate load. The difficulty though, is that what I can read from the channel is a chunk of binary data, possibly incomplete, and that possibly doesn't even translate to valid chars (for example, a 16-bits char may be cut in-between and I get only the first byte).
    That orients me to a binary protocol (at least, to a protocol where I can identify "end of message " markers at the binary level).
    Alternately, if I can ensure all my messages fit a UDP packet, I'd better stuff the String in a UDP packet on the client end, and decode a String from the UDP received (atomically) on the server end.
    I'd lose TCP's relative reliability, but simplify the programming model for the protocol handling...
    I'm still free to choose the transport at this step of the project...
    Any recommendation?

  • Use same SSLSession for another port

    Hi!
    The SSLContext determines onto the host and the port wether a SSLSession is available for resuming or not. Now i want to use one Session for the same host but a different port. Is there any way to do this? The port is nowhere exposed and i can�t find an entrypoint where to customize sth in order to allow the same session for another port.
    Azrael

    i tried version (a) with different port-combinations but i didn�t have any luck. so i informed myself about sslengine. Found a good guide for it and it doesn�t look that bad, altough all the handshake and lengthy-task problems.
    The big problem is now for me: how will it be determined here which sesions to resume? again only through the host and port you give when creating the engine? then it�ll be quite easy to solve my problem.
    thanks already for the answer
    Azrael
    btw: it�ll be also interesting for me to either implement the sslengine into synchonous sockets and/or learn asynchronous sockets in java.

  • Swing eating up system resources

    I'm developing a chat system with a client and server. The server simply listens for clients and relays chat messages. The client consists of a chat gui and the main server process.
    My server runs fine; my client however causes the system to slow. I'm using Windows XP Service Pack 2, and when I turn on System Monitor both the server and client are running at 40-50% system usage (without the client connected my server runs 0%). Although the client gui is smooth, other applications are laggy. Profilling my client, I see that its spending most of its time in sun.awt.windows.WToolkit.run (cpu=times). For cpu=samples, most of the CPU usage is used in WToolkit.eventHandler.
    here's how my client works:
    First it starts the Client object, which initiates a connection. Once the connection is established, it launches the chat GUI (I'm using New I/O - asynchronous sockets here). Obviously the chat GUI is in its own thread. Originally I had separate thread for the Client object, but seeing terribel performance I merged the client object back into the main thread, but to no avail.
    My Chat GUI class has two handlers - an ActionListener which listens for the user typing in enter to send a message, and a windowlistener, which listens for a close.
    Any help will be appreciated. Thanks!

    For fastest, most efficient answers to questions like this come to the ClamXav Forum first.
    lnbstahl wrote:
    Well, thanks for the reply, but Intego isn't what's using my resources, so at least it's got that going for it.  Can anything be done about the clamscan or ClamXav?  Can it be killed?  I'm use Parallels, but it's not currently running.  I have seen that ClamXav is installed, but as I said, I didn't install it, so wonder why it's now running and dominating my system resources.
    ClamXav cannot install itself and I'm not aware of any other installer that includes it, so it must have either been downloaded from the AppStore or a web site. Please highlight the application, hold the command key down and type the I key (that's eye, not ell) to bring up the "Get Info..." dialog and tell me what it says is the version number.
    I don't believe it's possible for the clamscan process to run without the application being used, so in Activity Monitor type the letters "clam" without the quotes in the search box in the upper right corner of the window and tell me everything running with clam in the name.  If the process is clamdscan, that would indicate that you are running ClamXav Sentry in the background which would also be running the clamd process.

  • NSFileHandle freezes when receiving too much data?

    Hi,
    I am running two applications, on 2 separate stations.
    The first one which is an iPhone (OS2.2)
    The seconde one a PC computer (Win XP)
    The iPhone is a Client whose communication is managed by NSFileHandle.
    The PC is using an Asynchronous socket class and acting as a Server.
    It's mainly a one-way TCP communication : the data are sent by the PC server to the iPhone Client.
    Now : as long as the amount of data does not overflow some stack (which I don't know), the server app runs well, and the client deals with incoming Data without a pb.
    But as soon as this "stack" is overflowed, Servers skips some sending (to avoid blocing a in a non blocing mode), which is not really a problem since I can afford loosing some data, but I also have odd behaviors that are not the same on Iphone or iPhone Simulator, but have obviously the same source :
    - the iPhone Client runs normally (even during the overflow) until the App suddenly closes on its own. While it is running, and until it stops, it receives and processes -with no evident problem- incoming data (those that have been successfully sent by the Server).
    - the iPhone Simulator suddenly freezes : when I pause it, it appears that it is always stucked in the [MyNsFileHandle readDataOfLengh:MySize];, though I thought it should return an empty NSData instead of freezing.
    Since I have sent lot of data, I know they are available... but it looks like they are not. I also thought that NSFileHandle's - (NSData *)readDataOfLength:(NSUInteger)length would raise some kind of exception in case of a problem (such as described in the Message documentation), but instead of it, it is just stucked here.
    Then, I wonder if there is a way to manage such a data Overflow so that I can avoid the app to crash or freeze
    Since I am also uneasy with Apple exceptions, it is possible that I actually don't look well although some are raised here. In such a case, could you explain to me how to catch them?
    I hope I gave sufficient information about my problem. If I happened to have not, don't hesitate to ask for more about it.

    If there any pattern to what applications you have open when you get the freezing? You will probably find it's an application rather than the application switcher itself. Also, check your Dashboard widgets. If you are using 3rd party widgets try closing them and see if the problem goes away.
    You can also try deleting your Finder preferences by dragging the file…
    ~/Library/Preferences/com.apple.finder.plist
    … to the Trash (don't empty it just yet) and then immediately restarting and see if that makes a difference.

  • Jdb option not recognized! Is this a bug?

    The userguide of the JPDA on URL http://java.sun.com/products/jpda/doc/conninv.html
    states:
    In JDB, the -attach option provides access to one of the attaching connectors in the reference implementation (shared memory on Win32, sockets on Solaris). The -listen option provides access to one of the listening connectors in the reference implementation (shared memory on Win32, sockets on Solaris). A class name and arguments specified directly on the command line provide access to the Sun command line launching connector.
    For example:
    jdb -attach myhost:8000
    is an easy way to attach to a target VM with the Socket Attaching Connector (on Solaris), and
    jdb Hello 1 2 3
    is an easy way to launch a target VM with the Sun Command Line Launching Connector.
    However, the -connect option is also provided by JDB to handle any connector by taking an connector name and a set of arbitrary name/value argument pairs. For example the command lines above have the following equivalents.
    jdb -connect com.sun.jdi.SocketAttach:host=myhost,port=8000
    jdb -connect "com.sun.jdi.CommandLineLaunch:main=Hello 1 2 3"
    However, when I invoke this:
    M:\ZE0510_view\LAB>jdb -connect com.sun.jdi.SocketAttach:host=localhost,port=1210
    I get this:
    Internal exception: java.lang.IllegalArgumentException: Argument hostis not def
    ined for connector: com.sun.jdi.SocketAttach
    at com.sun.tools.example.debug.tty.VMConnection.parseConnectorArgs(VMCon
    nection.java:101)
    at com.sun.tools.example.debug.tty.VMConnection.<init>(VMConnection.java
    :128)
    at com.sun.tools.example.debug.tty.Env.init(Env.java:66)
    at com.sun.tools.example.debug.tty.TTY.main(TTY.java:923)
    So it seems we have a problem here, or do I ovelook something?
    Kind regards,
    Marcel Zeeuw
    Amsterdam
    the Netherlands

    The manual states the following example:
    jdb -connect com.sun.jdi.SocketAttach:host=myhost,port=8000
    This should be:
    jdb -connect com.sun.jdi.SocketAttach:hostname=myhost,port=8000
    Marcel Zeeuw

Maybe you are looking for