UDP Server/Client Question

Hi All,
I'm just starting to work on this new server/client app and very new to UDP. Right now, I'm trying to read up on it. I'm wondering if anyone can point me to some good reading material. Quick question though, if a server (c-based) sends several messages, one right after another, can a client (java-based) handles these messages? I don't have any code to post just yet, still in the designing part. Thanks!

Go for, JSP and Servlet ( Sun Microsystems )
or Professional Java Server Programming wrox

Similar Messages

  • Need Help for client - server - client question [Sockets]

    Hi
    I have read the http://java.sun.com/docs/books/tutorial/networking/sockets/index.html tutorial and made this Knock Knock Application.
    But now, I want that one client can view all the other clients which are connected to the server, and interract with a selected cleint over the server (client - server - client).
    But I have no idea how to build such a registration concept?
    A concrete hint (or link) how to realise this would be very helpful. I searched all the internet for examples, but I dont found a simple example.
    Thanks in advance
    greeds

    wSam,
    It appears that Sun considers RMI to be simpler, although less efficient than the alternative:
    http://java.sun.com/developer/technicalArticles/ALT/sockets/
    This article also talks about object serialization, which I am a fan of. Suppose that you want to send a data structure containing lots of information (like all connected users). You can actually pass an object (rather than text) across the network using ObjectOutputStream and receive it on the other end with ObjectInputStream. You might create your own Command class for passing objects between the client and server instead of using RMI. The Command class might hold flags that indicate which method should take place on the remote machine (i.e. send chess move command).

  • JDeveloper 11g & ADF: supported version of svn server/client question

    Hi all,
    I would like to setup a repository for our dev team, we are coming from jdev 10g with svn server 1.3.2 and tortise svn 1.4.8. After reading through John Stegeman's ADF Development Essentials documents, I noticed this article was published back in 2008 and the supported version at that time was 1.4x. What is the current supported svn server and client (i would like to use tortise svn in conjunction with jdev plugin) version for JDeveloper 11g?
    Thanks,
    Wes

    Check out this: http://www.oracle.com/technetwork/developer-tools/jdev/index-091111.html
    For 11.1.1.4:
    Subversion 1.5, SVNKit 1.2
    Subversion 1.6 2 , SVNKit 1.3 2
    GNU CVS 1.11, CVSNT 2.5
    Amit

  • Beginner: Server/Client question

    I want to have a Server application and a Client application running on the same machine both of them with a Listener (thread). Can both of them be Listening on the same port? I think that if I did that the sending application would receive the message right back sense it is listening to the port it sent the message to.
    How is this usually done?
    Thanks,
    Andrew

    No they do not listen on the same port but typically you only need to establish a specific port for the server. The the client can connect to the server on that port but it's side of the connection will be running off a different port that is selected from the availible ports for you. You can find out what the client port is if you want though I do not remeber the specific method calls to do so.

  • Help needed in receiving  two consecutive msges from SIP Ser in UDP server!

    Hi everyone,
    I am Mitul Gogoi,from Assam,North-east part of India.
    I am writing a SIP proxy server,which is simly a UDP server and which will sit between the Client(X-Lite softphone) and Brekeke SIP Server and just receive and send messages.
    Client---------------->My UDP Server-------------------------->SIP Server (This is for requests)
    again,
    SIP Server---------->My UDP Server-------------------------->Client (This is for responses)
    (couldnot draw the arrows together)
    My server will receive any msg coming from Client in port 7000 from Client and My server will send the msg to SIP Server to its IP address and port 5060.So, I just wanted to change the port number to which Client will send msges;i.e. instead of earlier port 5060,it will now send to port 7000.
    The msg sending and receiving scenerio:
    1.The first msg from Client is received by My Server.
    2.My server sends the msg to SIP Server.
    3.My server then waits for response from SIP server.
    4.One msg comes to My server and received successfully. and it closes the socket.
    5.This msg is sent to Client.
    6.Second msg comes from SIP server to My server.But My server is unable to receive this second msg.maybe because My server closes the socket to receive the next msg.
    I am using ResponseHandler Thread in main which will listen to any msges that may come from SIP server to My server.
    My question is :
    Is it not possible to receive two consecutive msg from SIP server ?
    If one msg comes,it then closes the socket.
    My code for sending and receiving :
    udpClSocket = new DatagramSocket();
    packet = new DatagramPacket(buf, buf.length,InetAddress.getByName(server), port);
    udpClSocket.send(packet);//it will send to SIP Server as well as Client,by changing the server and port
    byte resbuf[] = new byte[msgSize];
    packet = new DatagramPacket(resbuf, resbuf.length);
    udpClSocket.receive(packet);//it will receive msg from SIP server only
    packet = null;
    udpClSocket.close();
    The first msg comes to My server successfully,but the second msg is not being received.
    I have tried in so many ways,such as taking two different ports :one for receiving for Client and My server ,and another port for My server and SIP server.
    If anyone can help me in this ,then I will be highly grateful.
    regards,
    Mitul

    Why? Throw all this code away, and use the NIST reference implementation of JAIN-SIP. They've done all the hard work for you. All you have to do to write a stateless proxy is a little mild header processing.
    Thank you ejp for your reply.Mine is a Outbound SIP proxy server,which uses a port other than default 5060 SIP server port.The client will REGISTER SIP server via my server.and moreover,I want to build my own server at least once for learning purpose.
    maybe because My server closes the socket to receive the next msg.
    Why?
    I donot know why.may be I am very new to network programming or did not do much research in networking.But,my code should work;couldn't find out any fault.
    Here is my code:
    package com.ef;
    import java.net.DatagramPacket;
    import java.net.DatagramSocket;
    import java.net.InetAddress;
    import java.util.Date;
    * It sends UDP packets to following destinations-
    * 1. SIP Server
    * 2. SIP UACs
    public class OBUDPClient extends Thread {
         private DatagramSocket udpClSocket;
         private DatagramPacket packet;
         private String server = "192.168.1.2";//IP of Brekeke SIP server
         private int port = 5060;
    //SIP Message Size
         private int msgSize = 2048;
         private byte buf[];
         private boolean serFlag = true;
         private OBMessage m;
         * Send Request to SIP Server
         * @param in_packet
         * @throws Exception
         public OBUDPClient(DatagramPacket in_packet) throws Exception{
              super("Client-"+String.valueOf((new Date()).getTime()));
              this.buf = in_packet.getData();
              m = new OBMessage();
              * Keep track of IP and Port of the source of this packet. Response
              * from SIP Server will be redirected to this IP and Port
              m.setTargetIP(in_packet.getAddress().getHostAddress());
              m.setTargetPort(in_packet.getPort());
              start();
         * Send Request to SIP UAC (). This constructor gets call from OBResponseHandler.java
         * @param server
         * @param port
         * @param buf
         * @throws Exception
         public OBUDPClient(String server, int port, byte buf[]) throws Exception{
              super(String.valueOf((new Date()).getTime()));
              this.server = server;
              this.port = port;
              this.buf = buf;
              serFlag = false;
              start();
         public void run(){
              try{
              System.out.println("OBUDPClient Redirecting packet");
              udpClSocket = new DatagramSocket();
              //Send Request
              packet = new DatagramPacket(buf, buf.length,InetAddress.getByName(server), port);
              udpClSocket.send(packet);
              //Receive Response
              byte resbuf[] = new byte[msgSize];
              packet = new DatagramPacket(resbuf, resbuf.length);
              udpClSocket.receive(packet); //could not receive two consecutive msg from SIP server
              if(serFlag){
              * If request is sent to SIP Server we are interested for the
              * response otherwise not
              System.out.println("<----------------Handle Response----------------->");
         System.out.println("++++++++++++++++++++++++++++++++++++++++++++++++++");
         System.out.println("Response from SIP Server: "+new String(packet.getData()).trim());
         System.out.println("++++++++++++++++++++++++++++++++++++++++++++++++++");
         //Read SIP reseponse sent by SIP Server
         m.setMessage(new String(packet.getData()).trim());
         //Store the Response message in Queue
         OBMain.q.push(m);
         }catch(Exception ex){
         ex.printStackTrace();
         packet = null;
         udpClSocket.close();
    Note:Everything starts from the Client.First,Client makes a REGISTER request;it is passed through Outbound server to SIP server.Then,SIP server responds with 100 Trying;this is received successfully by my outbound server and sent to Client.Then,again,SIP server responds with 200 OK;this is not received by my outbound server;hence cannot reach Client,as a result of which Registration fails.
    regards,
    mitul

  • Can i run UDP  client and UDP  server socket program in the same pc ?

    hi all.
    when i execute my UDP client socket program and UDP server socket program in the same pc ,
    It's will shown the error msg :
    "Address already in use: Cannot bind"
    but if i run UDP client socket program in the remote pc and UDP server socket program run in local pc , it's will success.
    anybody know what's going on ?
    any help will be appreciated !

    bobby92 wrote:
    i have use a specified port for UDP server side , and for client define the server port "DatagramSocket clientSocket= new DatagramSocket(Server_PORT);"Why? The port you provide here is not the target port. It's the local port you listen on. That's only necessary when you want other hosts to connect to you (i.e. when you're acting as a server).
    The server should be using that constructor, the client should not be specifying a port.
    so when i start the udp server code to listen in local pc , then when i start UDP client code in local pc ,i will get the error "Address already in use: Cannot bind"Because your client tries to bind to the same port that the server already bound to.

  • UDP server and client

    Hi
    I have some problems with making the udp server and client. I must receive acknowledgement and if it will not come in timeout, I want to resend the packet... But I don't know how can I go to another state, when program is waiting for acknowledgement...
    Thanks

    Hm... It is something I have to do... (udp) I haven't any other choice, that's work from school.

  • TCP client communicating with UDP server

    Hello,
    I want to make a TCP client to communicate with an UDP server. Does anyone know a way of doing this? I am not interested in reliable data transfer. So I don't care if the datagram is lost. I want to make the UDP server accept some datagrams from the TCP client. Also, the datagram that I want to transmit is less than 65,536 octets so it is not devided to several datagrams. Therefore, only one exchange procedure occurs.
    I made an UDP server using DatagramSocket and DatagramPacket classes and a TCP client using Socket class, but the TCP client informs me that the connection was refused.
    Any ideas?

    Let's google for IP header and the first hit is http://www.networksorcery.com/enp/protocol/ip.htm (Whoa! Classic page! I must have seen that back when googling was called altavista.)
    There is a header field, a single byte, called protocol. For TCP/IP that field contains 6, for UDP/IP it contains 17.
    If you send a packet with protocol=17, the receiving host's kernel will check if it has an process listening to UDP (17) at the port specified in the packet header. No such process? Then simply discard the packet. So you can't send an UDP packet to a TCP socket because the protocol field is wrong.
    If you want to fake a TCP stream you could look into jpcap, which allows you to capture and send raw packets. Google for it; and pick the right jpcap, there are two, only one of which (AFAIK) can send packets. Attempting to write your own TCP implementation is highly advanced though, and not really practical.

  • \\SERVER\Clients\Setup\setup.exe with Windows Vista Error

    I added the first Vista client to an SBS 2003, SP1 domain.  Until now, all clients were WinXP, SP2.  Office 2003 is installed on the XP clients, and the Vista client, which may not be pertinent to this problem.
    As is normal, "\\SERVER\Clients\Setup\setup.exe /s SERVER" is executed when a user logs on to any domain client.  On the Vista client, I always get the dialog -- regardless of the account privilege -- asking for permission to run Setup.exe.  It is annoying.  Occasionally, the Program Compatiblity Assistant will appear and advise there's a known compatiblity issue with Setup.exe.  It points to KB article 926505 for resolution.  The title of the KB is, "Windows Small Business Server 2003: Windows Vista and Outlook 2007 compatibility update."
    When I run the SBS2003SP1-KB926505-X86-ENU.EXE fix, I get the error:  "This update cannot be installed.  Either it is already installed as part of an existing service pack, or it requires a more recent service pack.  For more information, see the systems requirements on the download page."
    I installed Windows Server 2003 SP2 and run the KB926505 fix, but I get the same error  "This update cannot be installed.  Either it is already installed as part of an existing service pack" After a reboot of te SBS server the same  problem on the Vista client, I always get the dialog -- regardless of the account privilege -- asking for permission to run Setup.exe.  It is annoying.  Occasionally, the Program Compatiblity Assistant will appear and advise there's a known compatiblity issue with Setup.exe.  It points to KB article 926505 for resolution.
    The problem is Windows Vista Business, because all windows XP clients have no problem at all.

    PNP,
    You do not say whether if you accept the permission dialog whether the setup continues or not, but the short answer to the question revolves around UAC.
    Remember that EVERY user (except the actual Administrator account) has only Standard user rights regardless of group.  When a task that requires Admin rights is executed, one of three things will happen: 1) If you are THE Administrator, then your task will continue.  2) If you have Admin rights, you will be prompted that a process is trying to use elevated rights and ask for permission, or 3) If you are a Standard user, you will either be denied flatly or prompted to supply credentials.  Which of these happen depend on GPO settings, but the default is to prompt.
    In any event, I believe that this is what you are running into, and is one of the big feature improvements in Vista.  Yes, it can be a bit annoying (Try deleting an "All Users" icon from the Start Menu!) but is there to place one more barrier between virus and malware writers and your OS.
    If it's TOO annoying to bear, you can turn off UAC by going into your profile and disabling it. (It requires Admin rights, of course. )  It is not recommended as you do a very effective job or nutering the Vista Security Model by doing so.
    If it, of course, your choice.  we IT Admins have a lot more issues with this than the standard user, but for me, I gladly take the tradeoff because I worry a lot less about those few I HAVE to give Admin rights to.
    Good luck!

  • Non-blocking Server/Client is blocking...?!

    First, a simple question:
    Why in most example code using Selectors, when iterating over the Set returned by Selector.selectedKeys() does the currently selected SelectionKey get removed from the Iterator? I see it all the time, but since the SelectionKey is still bound to the underlying Selector it seems to not really do anything.
    Now to my main problem:
    I been working with 1.4 for a week now trying to implement a simple test server/client, whereby the server constantly sends out the current time to any subscribing clients, who in turn display the time to stdout. Pretty straight forward, huh?
    Well, everything seems to go fine...once. The Server accepts the client connection, sends out a the current time, the client (only one for now) receives it, displays to the screen, but then both server and client block on the Selector.select() method.
    If I shut down the client, the server then continues through the select() method, finding one SelectionKey, tries to write to it and throws an IOException (since the client is no more). I'm catching that exception and then removing the channel from the Selector, so that the server may continue to service requests.
    When starting a second client while the first is still running causes the following sequence of events:
    Server: starts up
    ClientA: connects to server
    Server: broadcasts the time
    ClientA: displays time
    // nothing else happens until...
    ClientB: connects to server
    Server: broadcasts the time
    ClientA: displays time
    ClientB: displays time
    //everything blocks again...
    ClientA: disconnects from server
    Server: broadcasts the time
    ClientB: displays time
    As you can see it seems everything blocks until a client does something (connect/disconnect).
    I will post code if anyone asks, but I don't want to spam the board if no one is willing to help me.
    -Justin

    You got it!
    //   ********** SERVER **********
    import java.io.IOException;
    import java.net.InetSocketAddress;
    import java.net.ServerSocket;
    import java.net.Socket;
    import java.nio.ByteBuffer;
    import java.nio.channels.CancelledKeyException;
    import java.nio.channels.SelectionKey;
    import java.nio.channels.Selector;
    import java.nio.channels.ServerSocketChannel;
    import java.nio.channels.SocketChannel;
    import java.util.Date;
    import java.util.Iterator;
    import java.util.LinkedList;
    import java.util.Set;
    public class TestServer
      private static final int DEFAULT_PORT = 9999;
      public static void main(String[] args)
        TestServer s = new TestServer();
      }//end of main(String[])
      public TestServer()
        this(DEFAULT_PORT);
      }// end of TestServer()
      public TestServer(int port)
        InetSocketAddress addr = new InetSocketAddress(port);
        try
          Selector acceptSelector = Selector.open();
          Selector broadcastSelector = Selector.open();
          ConnectionList connections = new ConnectionList(broadcastSelector);
          Acceptor a = new Acceptor(acceptSelector, addr, connections);
          Broadcaster b = new Broadcaster(broadcastSelector, connections);
          a.start();
          b.start();
        }// end of try
        catch (Exception ex)
          ex.printStackTrace();
        }// end of catch
      }// end of TestServer(int)
      private static String status(Selector s)
        StringBuffer sb = new StringBuffer(100);
        sb.append("Selector: ");
        Set keys = s.keys();
        sb.append("\n\tNum Keys: ");
        sb.append(keys.size());
        Iterator iter = keys.iterator();
        int i = 0;
        while (iter.hasNext())
          try
            sb.append("\n\t[");
            sb.append(i++);
            sb.append("]:");
            SelectionKey key = (SelectionKey)iter.next();
            sb.append(" acceptable=");
            sb.append(key.isAcceptable());
            sb.append(" connectable=");
            sb.append(key.isConnectable());
            sb.append(" readable=");
            sb.append(key.isReadable());
            sb.append(" writable=");
            sb.append(key.isWritable());
          }// end of try
          catch (CancelledKeyException cke)
            sb.append("*** CANCELLED KEY");
          }// end of catch
        }// end of while
        return sb.toString();
      }// end of status(Selector)
      class Broadcaster extends Thread
        private final String TF = Broadcaster.class.getName();
        private int BUFFER_SIZE = 2048;
        private Selector selector_;
        private ConnectionList connections_;
        private ByteBuffer buffer_;
        public Broadcaster(Selector selector, ConnectionList connections)
          super("Broadcaster");
          selector_ = selector;
          connections_ = connections;
          buffer_ = ByteBuffer.allocateDirect(BUFFER_SIZE);
        public void run()
          while (true)
            try
              registerNewChannels();
              System.out.println("BroadcasterThread: Before select() "+status(selector_));
              System.out.println("BroadcasterThread: Selecting...");
              int keysReady = selector_.select();
              System.out.println("BroadcasterThread: After select() "+status(selector_));
              System.out.println("BroadcasterThread: "+keysReady+" ready Key(s)");
              if (keysReady > 0)
                transmit();
              }// end of if
            }// end of try
            catch (Exception ex)
              ex.printStackTrace();
              return;
            }// end of catch
          }// end of while
        protected void registerNewChannels()
        throws Exception
          SocketChannel channel = null;
          while (null != (channel = connections_.removeFirst()))
            channel.configureBlocking(false);
            channel.register(selector_, SelectionKey.OP_WRITE);
            System.out.println("BroadcasterThread: Registered connection from " + channel.socket().getInetAddress());
          }// end of while 
        }// end of registerNewChannels()
        public void transmit()
        throws Exception
          Set readyKeys = selector_.selectedKeys();
          System.out.println("BroadcasterThread: Selected Keys: "+readyKeys.size());
          SelectionKey tempKey = null;
          SocketChannel tempChannel = null;
          fillBuffer();
          for (Iterator i = readyKeys.iterator(); i.hasNext(); )
            tempKey = (SelectionKey)i.next();
            tempChannel = (SocketChannel)tempKey.channel();
            if (tempKey.isWritable())
              System.out.println("BroadcasterThread: Key selected is Writable");
              try
                tempChannel.write(buffer_);
                System.out.println("BroadcasterThread: Sent message to "+tempChannel.socket().getInetAddress());
              }// end of try
              catch (IOException ioe)
                System.err.println("BroadcasterThread: Lost Connection");
                tempChannel.close();
              }// end of catch
            }// end of if
            else
              System.out.println("BroadcasterThread: Key selected is not Writable");
            }// end of else
          }// end of for
          buffer_.clear();
        }// end of transmit()
        private void fillBuffer()
          buffer_.clear();
          /* Place Date in Buffer */
          long time = System.currentTimeMillis();
          Date d = new Date(time);
          System.out.println("BroadcasterThread: Broadcasting "+d);
          String date = d.toString()+"\n";
          byte[] datebuff = date.getBytes();
          buffer_.put(datebuff);
          /* Prepare for read operations */
          buffer_.flip();
        }// end of fillBuffer()
      }//end of inner class Broadcaster
      class Acceptor extends Thread
        private Selector selector_;
        private ConnectionList connList_;
        private final String TF = Acceptor.class.getName();
        public Acceptor(Selector selector, InetSocketAddress address, ConnectionList connList)
          super("Acceptor");
          selector_ = selector;
          connList_ = connList;
          try
            ServerSocketChannel ssc = ServerSocketChannel.open();
            ssc.configureBlocking(false);
            ssc.socket().bind(address);
            System.out.println("AcceptorThread: Bound to " + address);
            ssc.register(selector_, SelectionKey.OP_ACCEPT);
          }// end of try
          catch (Exception ex)
            ex.printStackTrace();
          }// end of catch
        public void run()
          while (true)
            try
              System.out.println("AcceptorThread: Selecting...");
              int keysReady = selector_.select();// block till a channel is ready
              System.out.println("AcceptorThread: "+keysReady+" Keys Ready");
              if (keysReady > 0)
                acceptPendingConnections();
              }// end of if
            catch (Exception ex)
              ex.printStackTrace();
        protected void acceptPendingConnections()
        throws Exception
          Set readyKeys = selector_.selectedKeys();
          System.out.println("AcceptorThread: Selected "+readyKeys.size()+" Keys");
          for (Iterator i = readyKeys.iterator(); i.hasNext(); )
            SelectionKey key = (SelectionKey)i.next();
            i.remove();  
            ServerSocketChannel readyChannel = (ServerSocketChannel)key.channel();
            SocketChannel incomingChannel = readyChannel.accept();
            System.out.println("AcceptorThread: Connection from " + incomingChannel.socket().getInetAddress());
            connList_.add(incomingChannel);
          }// end of for
        }// end of acceptPendingConnections()
      }// end of inner class Acceptor
      class ConnectionList
        private LinkedList list_;
        private Selector selectorToNotify_;
        public ConnectionList(Selector toNotify)
          list_ = new LinkedList();
          selectorToNotify_ = toNotify;
        }// end of ConnectionList(Selector)
        public synchronized void add(SocketChannel newlyConnectedChannel)
          list_.add(newlyConnectedChannel);
          selectorToNotify_.wakeup();
        }// end of add(SocketChannel)
        public synchronized SocketChannel removeFirst()
          SocketChannel first = null;
          if (list_.size() > 0)
            first = (SocketChannel)list_.removeFirst();
          }//end of if
          return first;
        }// end of removeFirst()
      }// end of inner class ConnectionList
    }// end of class TestServer
    //   ********** CLIENT **********
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.net.InetSocketAddress;
    import java.nio.ByteBuffer;
    import java.nio.channels.CancelledKeyException;
    import java.nio.channels.Channels;
    import java.nio.channels.ReadableByteChannel;
    import java.nio.channels.SelectionKey;
    import java.nio.channels.Selector;
    import java.nio.channels.SocketChannel;
    import java.nio.channels.WritableByteChannel;
    import java.util.Iterator;
    import java.util.Set;
    public class TestClient
      public static final String TF = TestClient.class.getName();
      private static final String DEFAULT_SERVER_IP = "127.0.0.1";
      private static final int DEFAULT_SERVER_PORT = 9999;
      private InetSocketAddress serverAddr_; 
      private Selector connectSelector_;
      private Selector readSelector_; 
      private WritableByteChannel outputChannel_; 
      private ByteBuffer receiveBuffer_;
      private SocketChannel serverChannel_;
      public static void main(String[] args)
        TestClient c = new TestClient();
      }// end of main(String[])
      public TestClient()
        this(DEFAULT_SERVER_IP, DEFAULT_SERVER_PORT);
      }// end of TestClient()
      public TestClient(String ip, int port)
        try
          serverAddr_ = new InetSocketAddress(ip, port);
          connectSelector_ = Selector.open();
          readSelector_ = Selector.open();
          outputChannel_ = Channels.newChannel(System.out);
          receiveBuffer_ = ByteBuffer.allocateDirect(512);
          connect();
          run();
        }// end of try
        catch (Exception ex)
          ex.printStackTrace();
        }// end of catch
      }// end of TestClient(String, int)
      private void connect()
      throws Exception
        serverChannel_ = SocketChannel.open();
        serverChannel_.configureBlocking(false);
        serverChannel_.connect(serverAddr_);
        serverChannel_.register(connectSelector_, SelectionKey.OP_CONNECT);
        int numKeys = 0;
        while (numKeys <= 0)
          System.out.println("connect(): Selecting...");
          numKeys = connectSelector_.select();
          System.out.println("connect(): "+numKeys+" ready Key(s)");
          Set readyKeys = connectSelector_.selectedKeys();
          System.out.println("connect(): Selected Keys: "+readyKeys.size());
          if (numKeys > 0)
            SelectionKey tempKey = null;
            SocketChannel tempChannel = null;
            Iterator i = readyKeys.iterator();
            while (i.hasNext())
              tempKey = (SelectionKey)i.next(); 
              i.remove();  
              tempChannel = (SocketChannel)tempKey.channel();
              if (tempKey.isConnectable())
                System.out.println("connect(): Key selected is Connectable");
                if (tempChannel.isConnectionPending())
                  System.out.println("connect(): Connection Pending");
                  tempChannel.finishConnect();
                  System.out.println("connect(): Connection Completed");
                }// end of if
              }// end of if
              else
                System.out.println("connect(): Key selected is not Connectable");
              }// end of else
            }// end of while
          }// end of if
        }// end of while
      }// end of connect()
      private void run()
      throws Exception
        serverChannel_.register(readSelector_, SelectionKey.OP_READ);
        while (true)
          System.out.println("run(): Before select() "+status(readSelector_));
          System.out.println("run(): Selecting...");
          int numKeys = readSelector_.select();
          System.out.println("run(): After select() "+status(readSelector_));
          System.out.println("run(): "+numKeys+" Ready Key(s)");
          if (numKeys > 0)
            processKeys();
          }// end of if
        }// end of while
      }// end of run()
      private void processKeys()
      throws Exception
        Set readyKeys = readSelector_.selectedKeys();
        System.out.println("processKeys(): Selected Keys: "+readyKeys.size());
        SelectionKey tempKey = null;
        SocketChannel tempChannel = null;
        for (Iterator i = readyKeys.iterator(); i.hasNext(); )
          tempKey = (SelectionKey)i.next();
          tempChannel = (SocketChannel)tempKey.channel();
          if (tempKey.isReadable())
            System.out.println("processKeys(): Key selected is Readable");
            try
              tempChannel.read(receiveBuffer_);
              receiveBuffer_.flip();
              outputChannel_.write(receiveBuffer_);
              receiveBuffer_.clear();
            }// end of try
            catch (IOException ioe)
              System.out.println("processKeys(): Lost Connection");
              tempKey.cancel();
            }// end of catch
          }// end of if
          else
            System.out.println("processKeys(): Key selected is not Readable");
          }// end of else
        }// end of for
      }// end of processKeys()
      private static String status(Selector s)
        StringBuffer sb = new StringBuffer(100);
        sb.append("Selector: ");
        Set keys = s.keys();
        sb.append("\n\tNum Keys: ");
        sb.append(keys.size());
        Iterator iter = keys.iterator();
        int i = 0;
        while (iter.hasNext())
          try
            sb.append("\n\t[");
            sb.append(i++);
            sb.append("]:");
            SelectionKey key = (SelectionKey)iter.next();
            sb.append(" acceptable=");
            sb.append(key.isAcceptable());
            sb.append(" connectable=");
            sb.append(key.isConnectable());
            sb.append(" readable=");
            sb.append(key.isReadable());
            sb.append(" writable=");
            sb.append(key.isWritable());
          }// end of try
          catch (CancelledKeyException cke)
            sb.append("*** CANCELLED KEY");
          }// end of catch
        }// end of while
        return sb.toString();
      }// end of status(Selector)
    }// end of class TestClient

  • Create UDP server with glassfish/ejb

    Hi,
    I have a mobile application that's using GPRS to send UDP messages to an IP address - wast amount of ~1K text messages every second.
    I want to create a UDP server app using the JAVA EE technology.After getting the messages over UDP, I would like to convert them to JMS messages and place them in a queue for message-driven beans to pick them up one by one.
    Now, I'm not sure if I can do this with Glassfish .
    Can I somehow open a UDP port and listen for messages ?
    Or should I rather make a Java SE app which receives messages from client and passes them into the application server message queue?
    Thanks a lot !!

    Discussion in progress here: http://forums.java.net/jive/thread.jspa?threadID=30254&tstart=0

  • Python Server/Client Application Development

    Hey All!
    I am writing a basic proof of concept server/client application for a project I am working on.
    My goal is this:
    1) End user launches client.
    2) Client connects to server.
    3) User selects one or more files to send to server.
    4) Server saves a copy of each file.
    5) Server terminates connection.
    5) Server processes each file.
    6) Upon completion of the processing server sets a "processing completed flag."
    7) Client periodically checks with server for "processing completed flag."
    8) Client securely reconnects
    9) Client downloads processed files.
    I have no background in programming servers/clients so this will be a learning experience for me and the workflow described above may change as I learn more about how this all works. Currently my hope is to first implement a system that will stay connected while the files are processed and once I have a better understanding as to how that works I can add more complexity to the system.
    I will be writing this in Python 3.3 and the server will be hosted on a server which will (for now) be running Arch.
    This thread will act as a sort of development journal but feel free to comment or post suggestions. I will for sure have questions as I go along too!

    brettski wrote:Turns out the best way (so far as I can tell) is to go integer -> string -> byte and then byte -> string -> integer..
    Do you mean regular, non-byte strings? That cannot possibly be the best way to do it. It would be like using Russian as an intermediary language for translating Spanish to French.
    Maybe the following will set you on the right path:
    http://stackoverflow.com/questions/6187 … -in-python
    http://stackoverflow.com/questions/4445 … int-python
    Looking further, this is probably the right way to do it:
    some_int = 57
    bytes = struct.pack('i', bytes)
    sock.send(bytes)
    See http://docs.python.org/3/library/struct.html for details.
    As for threaded servers, you may find some useful examples here.

  • DC making query to port 53(udp) on client machines

    After some network troubleshooting with our network engineers it was noticed that the domain controllers were trying to make connections to port 53(udp) on client machines. There is nothing in DNS that would suggest there is a reason for this. Is this normal
    behavior? Has anyone else run in to this?
    Thanks

    Hi,
    I have been experienced if I disable the IPV6 on some DC, the port 389 will can’t be accessed, please confirm your IPV6 settings.
    The related KB:
    How to use Portqry to troubleshoot Active Directory connectivity issues
    http://support.microsoft.com/kb/816103/en-us
    How to configure a firewall for domains and trusts
    http://support.microsoft.com/?scid=kb%3Ben-us%3B179442&x=19&y=10
    Support for IPv6 in Windows Server 2008 R2 and Windows 7
    http://technet.microsoft.com/en-us/magazine/2009.07.cableguy.aspx
    Hope this helps.
    We
    are trying to better understand customer views on social support experience, so your participation in this
    interview project would be greatly appreciated if you have time.
    Thanks for helping make community forums a great place.

  • Server/client application

    i'm just starting to learn about server/client applications and i'm a little confused about actually implementing them.
    my client will be an applet which can be accessed over the internet. i want the applet to be able to read/write to the server.
    now my question is, how can i start up the server program?
    i would want it to initialize and run, only when the user has gone to the website that uses the applet.

    look at using a Servlet, running under Tomcat (download the Java Web Services Developer pack from java.sun.com
    here's what the servlet looks like:
    mport javax.servlet.*;
    import java.util.*;
    import java.net.*;
    public class ServletTest extends GenericServlet
    /** servlet is initialising */
    public void init()
    System.out.println("ServletTest initializing");
    /** servlet wascalled bt client */
    public void service(ServletRequest request,ServletResponse response)
    try
    byte[] data=new byte[100];
    ServletInputStream inputStream=request.getInputStream();
    int read=inputStream.read(data);
    String string=URLDecoder.decode(new String(data,0,read),"UTF-8");
    System.out.println("read "+read+" bytes: "+string);
    inputStream.close();
    ServletOutputStream outputStream=response.getOutputStream();
    Date date=new Date();
    outputStream.write(date.toString().getBytes());
    outputStream.close();
    catch(Exception ex)
    ex.printStackTrace();
    /** servlet is being destroyed */
    public void destroy()
    System.out.println("ServletTest terminating");
    here's what the client looks like:
    mport javax.servlet.*;
    import java.util.*;
    import java.net.*;
    public class ServletTest extends GenericServlet
    /** servlet is initialising */
    public void init()
    System.out.println("ServletTest initializing");
    /** servlet wascalled bt client */
    public void service(ServletRequest request,ServletResponse response)
    try
    byte[] data=new byte[100];
    ServletInputStream inputStream=request.getInputStream();
    int read=inputStream.read(data);
    String string=URLDecoder.decode(new String(data,0,read),"UTF-8");
    System.out.println("read "+read+" bytes: "+string);
    inputStream.close();
    ServletOutputStream outputStream=response.getOutputStream();
    Date date=new Date();
    outputStream.write(date.toString().getBytes());
    outputStream.close();
    catch(Exception ex)
    ex.printStackTrace();
    /** servlet is being destroyed */
    public void destroy()
    System.out.println("ServletTest terminating");

  • 9iR2 OLAP Reporting Server Capacity Question

    9iR2 OLAP Reporting Server Capacity Question
    We are running Oracle 9iR2 with OLAP.
    OS - RHEL3 AS
    SERVERS - Dell Poweredge 6600's
    cpu 4 x 2.4ghz
    24GB RAM
    1.5 TB space
    Our AWs are typically 30GB in size. My question is, what is my capacity of jdbc thin client user sessions per box? I haven't been able to find much documentation on scalability with large AWs and a large user base. We will need to host reports for 6000 users moving to 16000 by next year.
    We will be switching to 2x 1.6ghz 64bit opteron boxes this year sometime as well.

    9iR2 OLAP Reporting Server Capacity Question
    We are running Oracle 9iR2 with OLAP.
    OS - RHEL3 AS
    SERVERS - Dell Poweredge 6600's
    cpu 4 x 2.4ghz
    24GB RAM
    1.5 TB space
    Our AWs are typically 30GB in size. My question is, what is my capacity of jdbc thin client user sessions per box? I haven't been able to find much documentation on scalability with large AWs and a large user base. We will need to host reports for 6000 users moving to 16000 by next year.
    We will be switching to 2x 1.6ghz 64bit opteron boxes this year sometime as well.

Maybe you are looking for

  • Print PDF with special print options of Canon IR printer

    Hi, We have a collection (db driven) of PDF documents that we want to send to our network printers. Some document need a hole punch of some other specific printeroptions of a Canon IR printer. The ideal solutions is a windows application where i coul

  • Import of existing Contract in Sourcing 7.0

    Hi All, I am trying to upload existing contract document in the Sourcing 7.0. I have utilized the workbook provided by SAP in the reference guide for contract import. There are 3 section in the workbook. They are:- contracts, agreements, contract_lin

  • How do i sync a number of calenders instantaniously via internet?

    How do i sync a number of calenders instantaniously via internet?

  • Hp laserjet 2605 stop working

    Hi all... After one of latest upgrades (I don't know wich exactly), I'm unable to print with my HP Color Laserjet 2605dn, as a network printer. I tryed to reinstall hplip but nothing. I tryed to remove the printer (I use only cups web interface to ad

  • Zen Nano Plus- help can't turn it

    I bought a Zen Nano Plus back in May, it worked fine until now. Now it will turn on half way then shut right off. My computer will recognize it, but the software won't. i can use all the help.