Sockets and thread communication multiplexing?

Hello,
I need to implement a server which will have a maximum of 10 clients connected.
I wanted to go for classic blocking I/O because I won't have much clients.
My problem is that even if I accept() some sockets and then create a thread for each socket,
then I still need to communicate some data to the other threads, problem is that I am blocked
on the read() operation, how could I address this problem?
I mean, lets say I am thread1 and blocked on read() on my socket, now thread7 wants to tell
me something like a chat message coming from client he handles, how could thread7 manage
to wake thread1 and send him a message somehow?
I do not want to deal with NIO stuff if possible because I do not need to scale, I just have a
problem because I am stuck on the read.
I will run on Windows.
Thanks for help.
Edited by: Marzullo on Jul 15, 2010 1:05 PM

Fully answered in [your other thread|http://forums.sun.com/thread.jspa?threadID=5445070&messageID=11020688#11020688].
Please don't multipost, as it can lead to people wasting their time repeating others' answers.

Similar Messages

  • Implementing sockets and threads in a jframe gui program

    Hi, I am trying to find a solution to a problem I am having designing my instant messenger application.
    I am creating listening sockets and threads for each client logged into the system. i want to know if there is a way to listen to other clients request from the main gui and then if another client tries to establish a connection with me for example, a thread is created for that client and then my chat gui opens automatically has soon has the other client sends his or hers first text message to me.
    I am relatively new at socket programming has I am currently studying along this area. I know how to create threads and sockets but I am having trouble finding out a solution to my problem. Here is the code that I have done so far for the listening method from my main gui, and the thread class of what I have done so far.
    listening socket:
         private void listeningSocket()
                ServerSocket serverSocket = null;
                boolean listening = true;
                try
                    //listen in port 4444;
                    serverSocket = new ServerSocket(4444);
                catch(IOException x)
                    JOptionPane.showMessageDialog(null, "cannot listen to port 4444", null, JOptionPane.ERROR_MESSAGE);
                while(listening)
                    client_thread w;
                    try
                       w = new client_thread(serverSocket.accept(), jTextArea1);
                       Thread t = new Thread(w);
                       t.start();
                    catch(IOException x)
                         JOptionPane.showMessageDialog(null, "error, cannot start new thread", null, JOptionPane.ERROR_MESSAGE);
            }thread class:
    import java.io.*;
    import java.net.*;
    import javax.swing.*;
    import java.sql.*;
    import java.awt.event.*;
    * @author jonathan
    public class client_thread extends Thread
         //define new socket object
        private Socket client_user = null;
        private JTextArea textArea;
        public client_thread(Socket client_user, JTextArea textArea)
            this.client_user = client_user;
            this.textArea = textArea;
        public void run()
            BufferedReader in = null;
            PrintWriter out = null;
            String error = "error has occured, messege was not sent";
            String messege = null;
             try
                //create input and output streams
                in = new BufferedReader(new InputStreamReader (client_user.getInputStream()));
                out = new PrintWriter(client_user.getOutputStream(), true);
                while(true)
                   //read messege sent by user
                   messege = in.readLine();
                    //display messege in textfield
                   out.println(messege);
                   textArea.append(messege);
            catch (IOException e)
                //error messege
                JOptionPane.showMessageDialog(null, error, null, JOptionPane.ERROR_MESSAGE);
    }

    Seems like all you need to do is create a new dialog for each socket that is established. Your current design looks like it will attempt to use the same textarea for all the sockets.
    I would say in your thread class do the following:
    MyConversationDialog dialog = new MyConversationDialog();
    while(true)
                   //read messege sent by user
                   messege = in.readLine();
                    //display messege in textfield
                   out.println(messege);
                   dialog.setVisible (true);
                   dialog.addMessage (message);
                }

  • Multi channel design issue - sockets and threads

    How are multiple channels handled in a chat program? Does the server separate the channels by having a port open for each channel, or is it done some other way?
    Thanks

    Yes it is possible. A user is logged on as long as the applet has a socket connection that has passed the login phase.
    Keep a server on the web site that handles the chat stuff. If you want to show some statistics like the users logged on, you can access the server from your local web site and ask him what's going on.
    You can do this with an administrative command set (your statistics module has to login to the server just like a chatter), with a special tcp port or with thread communication. In the latter case server and servlet would have to reside in the same JVM which is not really trivial...
    Another approach is to write the statistics into a shared file, and read this file from your web server.
    -- Stephan

  • Socket and Thread Explanation

    I'm a little confused on the Socket stuff. I read some tutorials but wanted to make sure I understand. I'm using a simple client/server chat app as a reference.
    First the ServerSocket is just a connection to the port you want to listen on... I understand that. Is the Sockets... Socket s = ss.accept(); a tunnel to the port for data to travel on?
    Second.. When you create a Thread. This is the information that travels on these sockets? If that's the case I understand... But I have one question relating to some chat code I can't quite figure out.
    The simple chat program conists of a ChatServer, ServerThread and a Client.
    in the ChatServer it creates a ServerSocket and later on it looks for new connections for clients and then creates a ServerThread. What the heck is this for. From the code in the ServerThread it just handles incoming data and sends them back out. OK.
    But in the Client... it connects to this port and then creates it's own thread i.e. new Thread(this).start();
    Why ServerThread and then a Thread from the Client... Shouldn't there just be one?
    Sorry, I just can't get this.

    I'm a little confused on the Socket stuff. I read
    some tutorials but wanted to make sure I understand.
    I'm using a simple client/server chat app as a
    reference.
    First the ServerSocket is just a connection to the
    port you want to listen on... I understand that. Is
    the Sockets... Socket s = ss.accept(); a tunnel to
    the port for data to travel on?when the accept() method called, the server socket will start listening to the port for any connection. Once a connection established, this method will return a connected socket.
    >
    Second.. When you create a Thread. This is the
    information that travels on these sockets? If that's
    the case I understand... But I have one question
    relating to some chat code I can't quite figure out.A new thread was created here to that this thread can handle the socket return by the serversocket independenty to the main thread. Mainly server code will do this so that the main thread can continue to listening to other new connection agains while this newly created thread will handle any communication between a connected client and server.
    The simple chat program conists of a ChatServer,
    ServerThread and a Client.
    in the ChatServer it creates a ServerSocket and later
    on it looks for new connections for clients and then
    creates a ServerThread. What the heck is this for.
    From the code in the ServerThread it just handles
    incoming data and sends them back out. OK.
    But in the Client... it connects to this port and then
    creates it's own thread i.e. new Thread(this).start();Well, i dun know how the code for the client look like... but guessing that the client was implements Runnable. So, in the main method, it spawn a new thread and pass this class for this new thread to handle while the main thread maybe continue to do other things or just end after finish.
    >
    Why ServerThread and then a Thread from the Client...
    Shouldn't there just be one?
    Sorry, I just can't get this.Well, hope my explaination was clear enough... :P

  • Socket and Thread Question?

    I have a Server/Client app where the Client connects to the server and the server accepts the Client and starts a new thread for each client.
    Then the Server Thread waits for the Client to contact.
    I set the timeout on the Server socket to 30 seconds.
    but the Client could sit there idle for much longer.
    So on the client side i used a timer to send "-1" every 5 seconds.
    That way if the Server Thread times out i know the Client is not there and end the thread and close everything.
    Now on the client side i may send several strings in a row to the server so i do not want my "-1" timer (i'm still here) messages to get intermingled with regular Client messages so i set up a boolean variable like so:
        volatile private boolean out1busy = false;
        private synchronized boolean getOut1busy(){
         return out1busy;
        private synchronized void setOut1busy(boolean on){
         out1busy = on;
        }then before using the socket i do this:
            while (getOut1busy()) try { Thread.sleep(40); } catch (InterruptedException ex) {}
            setOut1busy(true);
            lobbyOut.println("-1");
            setOut1busy(false);I have been running this for over a year and have personally never had a problem but have had rare clients testing say their comp has suddenly bogged down and it seems like they are describing what might happen if Out1Busy is set to true and not set back to false.
    ive checked my code and like i say it has never happened to me BUT i feel like what i am doing here is not the right way and there is probably a much better way to accomplish this. It is the only place in my code i see the chance of an infinate loop occuring.
    So regardless of whether or not it is even causing a problem can anyone tell me if it might cause a problem and a better way to do it.

    how about this.
    everywhere that i send data to the server that is not already on the event dispatch thread i just put in an invoke later which wold execute it on the eventdispatch thread.
    that way all communication with the server would be done on the event dispatch thread.
    so if i click a button that sends several strings right in a row it would complete before the "-1" im still here message sent at the same time goes through.
    so even if i had two bits of code that send several strings that need to be received in a row they would not get intermingled as long as they were both executed within a invokelater or already executed on the event dispatch thread (like a mouse clicked or action performed)
    so in my case here i always contact the server in either a state changed, action performed, or mouseclicked except for the "-1" im still here message.
    are alll these (state changed, action performed, or mouseclicked) executed on the event dispatch thread?
    i just put the "-1" in an invoke later and take out all the sleep and outbusy variable stuff.

  • Problem with socket and Threads

    Hi,
    I have coded a package that sends an sms via a gateway.
    Here is what is happening:
    * I create a singleton of my SMSModule.
    * I create an sms object.
    * I put the object in a Queue.
    * I start a new Thread in my sms module that reads sms from queue.
    * I connect to sms gateway.
    * I send the sms.
    * I disconnect from socket! This is where things go wrong and I get the following error (see below).
    I have a zip file with the code so if you have time to take a look at it I would appreciate it.
    Anyway all hints are appreciated!
    //Mikael
    GOT: !LogoffConf:
    mSIP Kommando var: !LogoffConf
    CoolFlix log: MSIPProtocolHandler;setLoggedin(false)
    We got LogOffConf
    Waiting ......for thread to die
    java.net.SocketException: Socket operation on nonsocket: JVM_recv in
    socket input stream read
    at java.net.SocketInputStream.socketRead0(Native Method)
    at java.net.SocketInputStream.read(SocketInputStream.java:116)
    at
    sun.nio.cs.StreamDecoder$CharsetSD.readBytes(StreamDecoder.java:405)

    Off the top of my head, probably the garbage collector cleared your SMSModule coz all classes loaded through other classloaders will be unloaded when that classloader is unloaded.
    mail in the code if you want me to look at it with greater detail.

  • Socket and threads.

    I have written a socket client and a socket server. The client sends a directory name and the server sends directory files and their content. The client asks for files every five seconds (it has to be made once every day, but for trials I have reduced the time), so I have written a thread to made the client sleep for that time. The problem appears after looping fifty or sixty times, when the socket, which does not die, stops making its work (files are not send any more). I really thank every answer.

    Please be clear. What "stops work" the client or the server? Can you post the relevant code that is "looping fifty or sixty times"?

  • Socket and Thread fun

    I am currently playing around with a, MUD like, program.
    I have 2 classes, server class who's main function is to listen to the port and create a new client class with the value of the incomming socket.
    The client class extends Thread, and pretty much just processes the input from the client socket.
    Now this is all good until I wanted to have multiple clients and have them talking to each other. I thought that having a Vector and storing the sockets in another class was the way to go. But whenever I refer to Vectors and Sockets I get the following runtime error :
    java.lang.NullPointerException
    at Controller.addSocket(ClientConnection.java:62)
    at ClientConnection.run(ClientConnection.java:35)
    Where line 35 is sending the socket to the class that adds it to the Vector, and 62 is trying to add the Socket to Vector.
    What am I doing wrong? Is there a better way of doing it, and if so a link to an example would be good.
    Cheers
    Shane

    From the stack traces, it is saying that the Controller is a null object. Probably you forgot to call on new Vector(), or you declared it twice in the constructor. There could also be a possibility that the socket passed to it was null.

  • Socket and Thread Problem

    When reading an Inputstream received after a connection has been established (throught a Socke connect) between a Server ands a Client , messages are being lost when a wait method is call. A client sents message which have to be processed and response sent back to the client . The message are encoded and as the code below shows each message ends with a '":" .Not only one message is sent at a time. and when messages are sent the client sometimes expect replies. This means that when a message is read , it be being processed by a Processor and until the reply has be sent this the thread reading the messages has to wait. when a reply is sent and the thread is waken up, the remaining the messages in the Input stream gets lost but the loop is not also exited since the end of the file is never reached.
    Solution:
    1. read a command message. if you find end of message, process the message and wait until you are notify and continue with the next command line
    public class Sender extends Thread {
         private Socket socket;
         private Processor processor = newProcessor();
         private boolean DEBUG = false;
         public Sender (Socket socket) {
              super();
              this.socket = socket;
              start();
         public void run() {
              while (true) {
                   if (processor .getStateOfProcess()&& socket != null) {
                        InputStream input = null;
                        try {
                             input = socket.getInputStream();
                             if (processor .dispatchMessage() != null) {
                                  socket.getOutputStream().write(
                                            CacheManager.dispatchMessage());
                                  processor .ClearMessage();
                        } catch (IOException ex) {
                        int i = 0;
                        char oldChar = ' ';
                        char c = ' ';
                        StringBuffer buffer = new StringBuffer();
                        try {
                             while ((i = input .read()) != -1) {
                                  c = (char) i;
                                  buffer.append(c);
                                                    if (c == ':' && oldChar != '\\') {
                                       processor .process(buffer.toString());
                                       buffer = new StringBuffer();
                                       c = ' ';
                                                              try {
                                            synchronized (this) {
                                                 wait();                         
                                       } catch (InterruptedException e1) {
                                                       if (processor.dispatchMessage() != null) {
                                            socket.getOutputStream().write(
                                                      CacheManager.dispatchMessage());
                                            processor.ClearMessage();
                                  oldChar = c;
                                    } catch (IOException e) {
       public void wakeup() {
              synchronized (this) {
                   notify();
    } This thread leaves that wait when the wakeup method is called in the Processor class.
    Question
    can some one help me figure out way and where the messages are being lost after the first message has been processed. why can the other message not be seen even other messages are still sent.
    What can be a possible solution
    thanks

    I didn't follow all of that, but I can see one serious error in your concurrent. You should always test the condition you're waiting for inside the synchronized block - otherwise you can't be certain that wait() is called before the corresponding notify() / notifyAll() call.

  • Sockets and net communication

    I got a project for school and i decided to program an net checkers game.
    I've looked up tutorial and found out some stuff on sockets but dont really understand how to send data from one computer to another.
    I need to send a string from one computer in the network to another, can anyone direct me to some source code or tutorial which will help me with this, or just help me in any way.

    What do you mean when you say client to client sockets? P2Pparhapse?
    I believe there is no such thing as client to client sockets... You'll need to create P2P architecture on your own if that is what you need...

  • Timer, socket, and thread

    I need to write a code that will open and write on/to a socket in less than two minutes. what classes should i have? I know I need the timer and socket, but which one should i use first? open a socket first than create a timer, or the other way? I'm new to this all OO stuff

    I need to write a code that will open and write on/to
    a socket in less than two minutes. ???
    what classes
    should i have? I know I need the timer and socket,
    but which one should i use first? open a socket first
    than create a timer, or the other way? I'm new to
    this all OO stuffhttp://java.sun.com/docs/books/tutorial/
    http://java.sun.com/docs/books/tutorial/essential/concurrency/
    http://www.particle.kth.se/~lindsey/JavaCourse/Book/Part1/Tech/Chapter08/timers.html
    http://java.sun.com/docs/books/tutorial/networking/sockets/index.html

  • Socket and Thread

    Hi,
    I am debugging a solution which had a filesend
    and dolisten method in the workchat project
    client: Project WorkChat
    https://docs.google.com/uc?authuser=0&id=0B3IOYEdd-pYSWVVtRzNHTGsxSjQ&export=download
    run the server before running this project
    and change the ip in the config point it to the server
    Also press enter in the right-top text box after typing the username,to start chat
    Double click to open private chat with another user.
    Drag and drop on user to send file
    server:
    https://drive.google.com/uc?authuser=0&id=0B3IOYEdd-pYSRjFyY0tKNmQ1bGc&export=download
    It is tough to test this solution and repair its filesend feature..
    Somehow it did work ,,but something went wrong of missing..
    I want to debug it and know what's not working in the filesend/dolisten methods.
    The rest of the code was derived from a vbsocket library which may now be unavailable through the MSDN
    Regards.
    Please remember to mark the replies as answers if they help and unmark them if they provide no help , or you may vote-up a helpful post

    Hello,
    I agree with Eason - you'd need to ask Google for help.
    Karl
    When you see answers and helpful posts, please click Vote As Helpful, Propose As Answer, and/or Mark As Answer.
    My Blog:http://unlockpowershell.wordpress.com
    My Book:Windows PowerShell 2.0 Bible
    My E-mail: -join ('6F6C646B61726C40686F746D61696C2E636F6D'-split'(?<=\G.{2})'|%{if($_){[char][int]"0x$_"}})

  • Conflict between socket and RMI

    Hi
    I wrote a program in client-server using socket and it was fine. I also wrote a client-server program using RMI. Fine as well. But after I connected the client-server using socket (open socket, send-receive messages, close socket), then use RMI. I got java.rmi.NotBoundException.
    Would anyone have a look and provide your feedback please? Thanks.
    big J
    *****************this is Server.java ***************************
    package single;
    import java.io.*;
    import java.rmi.Naming;
    import java.rmi.RemoteException;
    import java.net.*;
    import java.rmi.*;
    public class Server
    extends Thread {
    public static final int SOCKETPORT = 5555;
    private String serverName;
    public Server() throws IOException {
    System.out.println("*** socket opened ***");
    serverName = new String("localhost");
    ServerSocket serverSocket = new ServerSocket(SOCKETPORT);
    Socket socket = serverSocket.accept();
    InputStream is = socket.getInputStream();
    BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(is));
    System.out.println(bufferedReader.readLine());
    OutputStream os = socket.getOutputStream();
    PrintWriter printWriter = new PrintWriter(new OutputStreamWriter(os), true);
    printWriter.println("from server");
    os.close();
    is.close();
    socket.close();
    System.out.println("*** socket closed ***");
    public void runServer() {
    System.out.println("*** start of run():RMI ***");
    System.setSecurityManager(new SecurityManager());
    try {
    RMIInterfaceImpl rMIInterfaceImpl = new RMIInterfaceImpl();
    Naming.bind("//" + serverName + ":9999/RMIInterface", rMIInterfaceImpl);
    catch (RemoteException ex) {
    catch (MalformedURLException ex) {
    catch (AlreadyBoundException ex) {
    System.out.println("*** end of run():RMI ***");
    public static void main(String args[]) throws Exception {
    Server server = new Server();
    server.runServer();
    ******************this is Client.java **************************
    package single;
    import java.io.*;
    import java.net.*;
    import java.rmi.Naming;
    public class Client {
    private String serverName;
    private final static int SOCKETPORT = 5555;
    public Client() throws IOException {
    serverName = new String("localhost");
    Socket socket = new Socket(serverName, SOCKETPORT);
    OutputStream os = socket.getOutputStream();
    PrintWriter printWriter=new PrintWriter(os, true);
    printWriter.println("from client");
    InputStream is = socket.getInputStream();
    BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(is));
    System.out.println(bufferedReader.readLine());
    is.close();
    os.close();
    socket.close();
    public void runClient() throws Exception {
    System.out.println("*** start of runClient():RMI ***");
    System.setSecurityManager(new SecurityManager());
    RMIInterface rMIInterfaceImpl = (RMIInterface) Naming.lookup(
    "//" + serverName + ":9999/RMIInterface");
    String str = rMIInterfaceImpl.print();
    System.out.println(str);
    rMIInterfaceImpl.serverSide();
    System.out.println("*** end of runClient():RMI ***");
    public static void main(String args[]) throws Exception {
    Client client = new Client();
    client.runClient();
    ***************** this is RMIInterface.java ***********************
    package single;
    import java.rmi.Remote;
    import java.rmi.RemoteException;
    interface RMIInterface
    extends Remote {
    String print() throws RemoteException;
    void serverSide() throws RemoteException;
    ********************* this is RMIInterfaceImpl.java ***************
    package single;
    import java.rmi.RemoteException;
    import java.rmi.server.UnicastRemoteObject;
    public class RMIInterfaceImpl
    extends UnicastRemoteObject
    implements RMIInterface {
    public RMIInterfaceImpl() throws RemoteException {}
    public String print() {
    return new String("hello world");
    public void serverSide(){
    System.out.println("this should appear in serverside");

    I think you have a timing problem between your client and server. As soon as your client and server programs have finished their socket communication, they will both do their "runServer"/"runClient" methods. If the client attempts to lookup the server before the server has registered itself via Naming.bind(), I would expect that's why you're getting a NotBoundException in the client.
    You probably wouldn't use the design of your test client/server for something significant, but a quick and dirty way to make this work might be to have the client call Thread.sleep() for a few seconds before trying to do the lookup.

  • GPIB and RS232 communication problems

    I've been having several "interesting" problems with GPIB and RS232 communications in LabVIEW VIs.  Some I'll mention at the end for curiosity, but right now I'm facing a rather big problem.  I'm essentially self-taught at doing LabVIEW (using 8.5.1 right now), but by now I've had a lot of experience as their either has not been any drivers or pre-made VIs for the instruments I've needed or I've not been able to get the available drivers to work and had to write my own anyway (such as with the HP 3458A), but nothing seems to be working right now.  I'm not at work, but we typically find forum sites blocked anyway (I can't even download the NI drivers at work since they house them on a ftp server, go figures) so I can't give the VI itself (it wouldn't be easy to get approval even if I could) so the best I can do right now is in words describe everything I've tried.  I will be happy to post follow-ups of specific details if I can if they would be helpful.
    I've been working on a routine to read data from an MKS 670 Signal Conditioner/Display with a MKS 274 Multiplexer with 3 connected MKS 690A Baratrons.  Previously I've worked on programs using other older displays and the analog outputs which were being read by a DAQ card, but for a new project it was decided to try and just read the data directly.  I first worked with a unit with just an RS232 Serial Port which I managed to get to work, but had so much problems with garbage readings and having to add checks and re-reads that by the end no matter what delays I added between each reading and how simplified the command routine down to just 2 sequences and the read that it took at least 10 seconds to get 1 reading from each channel.
    Figuring maybe it was a limitation of the serial communications for these instruments I tried to re-work it for a unit with a GPIB port with which I'm actually much more familiar.  The problem is that I cannot get anything at all from the unit through GPIB.  Everything even the bare-bones built-in GPIB CLR function times out with no response from the instrument no matter how long I set the timeout limit and it also freezes the entire GPIB bus as well.  It isn't a waiting issue as it freezes on the very first command.  The GPIB initialization function seems to work (I typically find this to be unnecessary), but the instrument itself doesn't even respond with a status code.  I've also tried just the basic GPIB write functions with even just passing the <cr> and <lf> characters as well.  In Measurement and Automation Explorer most of the time the instrument won't even appear when doing search for instruments and when it does it shows as not responding to the *IDN? command (yes I've messed with the EOI, EOS, etc settings and I've even changed the GPIB address even though when it gets this far it confirms that I have the correct address) and even tried manually doing the *IDN?, *RST, and *CLR commands even with <cr> and <lf> characters which the manual for these units clearly states are compatible commands and NI SPY and everything show no response at all.  I've tried 2 different GPIB units, 3 different computers including several that are not online and haven't been updated for a while, and using older LabVIEW versions, extensive re-booting and resetting of computers and devices and still nothing.  I'm using an NI GPIB-USB-HS GPIB to USB adaptor which I've used extensively on other systems and even re-connected to those systems and everything worked fine.  When I hooked up equipment that I knew was working, it would either freeze the entire GPIB bus until well past whatever timeout setting I set at which point all the instruments would appear, but none responding to *IDN? queries or nothing would appear at all, or if I manually turned it off when frozen the other instruments would work and most even respond to the *IDN? queries.  The same goes for both of the GPIB instruments of this type that I tried and again for different versions of LabVIEW, difference computers (all Windows XP though), and every GPIB configuration setting I can find to mess with in every combination.
    Any thoughts or suggestions would be greatly appreciated.  I've had all sorts of weird problems with equipment and LabVIEW (you've got to love undocumented design features) that have frustrated me before, but I've never had an instrument never respond at all especially a GPIB one.  Getting garbage yes, no response at all, no.
    The side side issues I'm just mentioning as they may be related, but I'm really interested in the above as I have working solutions for these:
    One I've had is with a Hart Scientific (prior to being bought by Fluke) 1560 Black Stack that would continually stop responding to GPIB commands when on a continual read function taking readings just every 4 seconds with 250ms between each GPIB read or write command but for up to hours in total and the times it stops responding are random as far as I can tell.  I even started sending the *RST command before and after every read or write command and still it freezes.  The only thing is to manually turn it off and then back on or manually go through the menus and manually trigger the GPIB reset routine at which point it immediately starts responding.  However, when I got sick of having to babysit it and just decided to try the RS232 serial port (as that is all it has without the extended communications module) it works fine no problem and I can even get readings slightly faster from it.  Using a Hart Scientific 1529 Chub-e it could give me data on all 4 channels every second without problems.  I just find it a bit odd.
    When I couldn't get any of the HP 3458A driver packs to work to even give a single measurement reading and just made my own using basic GPIB read/write commands using the programming manual I still have a few interesting problems in randomly when reading off the full possible 256 bytes on the bus and clearing the bus I often find garbage partial readings on the bus every now and then.  I've added a few routines to do some basic checks, but it is annoying.  What is really weird is when just doing basic DC Voltage reads the "-" sign will randomly be dropped from some readings (started as about 1 out of every 5, down now to about 1 out of every 10).  Fortunately I'm taking several readings and averaging and taking the standard deviation with limits on the deviations and basically added a routine to say if there is even 1 negative number take the absolute value of all then make all negative, but again I find it weird.
    Thanks.
    -Leif
    Leif King
    Metrology Engineer
    Oak Ridge Metrology Center

    Greetings Leif,
    I understand you have completed extensive troubleshooting techniques to pin-point the problem with the GPIB communication. To begin, I want to ask you a few questions to help me understand your set-up and the issue at hand.
    1) Is the NI GPIB-USB-HS cable the one which cannot communicate with your instrument?
    2) When using the GPIB-USB-HS, does the GPIB interface show up in MAX?
    3) If yes, does the instrument appear in MAX after scanning for instruments (from what I understand in your issue, it does so in an intermittent manner..)?
    4) What driver version of VISA do you have installed in your computer?
    5) Are you able to communicate to the same instrument using another GPIB cable?
    Thank you for trying out some of these steps again, but we want to make sure we rule out other aspects in the systems which might be affecting the GPIB communication.
    As for your other issues, please post seperate threads for each so we can help you accordingly. Thanks!
    Sincerely,
    Aldo
    Aldo A
    Applications Engineer
    National Instruments

  • Socket and Security Policy

    I've tried to set experiment with Socket communication in Flex, but I keep hitting problems. Approach 1: in a Flex web app, I load a crossdomain security policy from a server. I then open a socket and write a few bytes to the server. In my server, I do not get the expected output on the stream--in fact, I get nothing at all--until I close the Flex application, at which point I get a seemingly inifinite stream of the bytes '0xEFBFBF'. Here's a hexdump view of a fragment of the data Flash Player sends to the server after I close the Flex app:
    00000130  ef bf bf ef bf bf ef bf  bf ef bf bf ef bf bf ef  |................|
    00000140  bf bf ef bf bf ef bf bf  ef bf bf ef bf bf ef bf  |................|
    00000150  bf ef bf bf ef bf bf ef  bf bf ef bf bf ef bf bf  |................|
    Approach 2: I then tried it in air, but although the connection seems to initiate properly and I can go through the above trivial client-server interaction, after a few seconds, I get a SecurityErrorEvent. From what I've been able to follow of the docs, Air applications are trusted in this respect, and should not need to load security policy, right? I tried to add a call to Security.loadPolicy(), but it seems to be ignored. This is the message flow:
    Received [class Event] connect
    Received [class ProgressEvent] socketData
    Received [class Event] close
    Received [class SecurityErrorEvent] securityError
    Security error: Error #2048: Security sandbox violation: app:/main.swf cannot load data from localhost:5432.
    The Air version of my client code is below:
    <?xml version="1.0" encoding="utf-8"?>
    <mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
    <mx:Script>
        <![CDATA[
            var str:Socket;
            private function handleClick(e:Event):void {
                Security.loadPolicyFile("xmlsocket://localhost:2525");           
                str = new Socket('localhost', 5555);
                var message:String = 'hello';
                for (var i:int = 0; i < message.length; i++) {
                    str.writeByte(message.charCodeAt(i));               
                str.writeByte(0);
                str.flush();
                str.addEventListener(Event.ACTIVATE, handleEvent);
                str.addEventListener(Event.CLOSE, handleEvent);
                str.addEventListener(Event.CONNECT, handleEvent);
                str.addEventListener(Event.DEACTIVATE, handleEvent);
                str.addEventListener(IOErrorEvent.IO_ERROR, handleEvent);
                str.addEventListener(ProgressEvent.SOCKET_DATA, handleEvent);
                str.addEventListener(SecurityErrorEvent.SECURITY_ERROR, handleEvent);           
            private function handleEvent(e:Event):void {
                 trace("Received", Object(e).constructor, e.type);
                 if (e is ProgressEvent) {
                     var strBytes:Array = [];
                     while(str.bytesAvailable > 0) {
                         var byte:int = str.readByte();
                         strBytes.push(byte);
                     trace(String.fromCharCode.apply(null, strBytes));
                 } else if (e is SecurityErrorEvent) {
                     trace("Security error:", SecurityErrorEvent(e).text);
        ]]>
    </mx:Script>
    <mx:Button label="test" click="handleClick(event)"/>   
    </mx:WindowedApplication>
    The server is in Java and is as follows:
    import java.net.*;
    import java.io.*;
    public class DeadSimpleServer implements Runnable {
        public static void main(String[] args) throws Exception {
            if (args.length != 2) {
                throw new Exception("Usage: DeadSimpleServer policy-port service-port");
            int policyPort = Integer.parseInt(args[0]);
            int servicePort = Integer.parseInt(args[1]);
            new Thread(new DeadSimpleServer(policyPort,
                                            "<?xml version=\"1.0\"?>\n" +
                                            "<cross-domain-policy>\n" +
                                            "<allow-access-from domain=\"*\" to-ports=\"" + servicePort + "\"/>\n" +
                                            "</cross-domain-policy>\n"
                       ).start();
            new Thread(new DeadSimpleServer(servicePort, "world")).start();
            while (true) Thread.sleep(1000);
        private int port;
        private String response;
        public DeadSimpleServer(int port, String response) {
            this.port = port;
            this.response = response;
        public String getName() {
            return DeadSimpleServer.class.getName() + ":" + port;
        public void run() {
            try {
                ServerSocket ss = new ServerSocket(port);
                while (true) {
                    Socket s = ss.accept();
                    System.out.println(getName() + " accepting connection to " + s.toString());
                    OutputStream outStr = s.getOutputStream();
                    InputStream inStr = s.getInputStream();
                    int character;
                    System.out.print(getName() + " received request: ");
                    while ((character = inStr.read()) != 0) {
                        System.out.print((char) character);
                    System.out.println();
                    Writer out = new OutputStreamWriter(outStr);
                    out.write(response);
                    System.out.println(getName() + " sent response: ");
                    System.out.println(response);
                    System.out.println(getName() + " closing connection");
                    out.flush();
                    out.close();
                    s.close();
            } catch (Exception e) {
                System.out.println(e);
    Am I missing something? From what I understand, either of these approaches should work, but I'm stuck with both. I have Flash Player 10,0,15,3 and am working with Flex / Air 3.0.0 under Linux.

    So... apparently, with the Air approach, this is what I was missing: http://www.ultrashock.com/forums/770036-post10.html
    It'd be nice if FlashPlayer gave us a nicer error here.
    I'm still trying to figure out what the heck is going on in the web app (i.e., non-Air Flex) example. If anyone has any suggestions, that would be very helpful.

Maybe you are looking for

  • How can I restore music from iPhone to iTunes Library?

    iTunes deleted music (the proverbial !) in my iTunes library, however the music (I want it in the library) still plays on my iPhone. I have repeatedly trying synching the iPhone (the music is still playing ok on the 3GS) but whenever I click on the s

  • Optical audio from Apple TV2 to receiver?

    I have an HDMI cable running from Apple TV to TV. I have a Toslink cable connected to receiver analog audio in (toslink -> mini-jack adapter). All the sound is currently going through TV. How do I get the sound to play on the receiver?

  • Flash 9.0r48 no audio with video

    I have just downloaded and installed the latest Flash player on my system (Red Hat Fedora Core 3 Linux, AMD Athlon 64 (cpuid is x86_64)). This version has exactly the same problem that earlier versions had, namely that there is no audio (sound) with

  • Power Cable issue with NOMAD

    I've had my nomad zen for over 2 years and it's worked great. However yesterday i went to plug it in to charge and no power was going into it. I felt the mid cable box (which i think converts AC to DC) and it was warm. So this a.m. i tried charging a

  • Cannot start Web Cache in Oracle 10g App Server

    Hi, Our Application runs on Oracle10g App Server, When it tried to start WebCache using the command opmnctl startproc ias-component=WebCache process-type=WebCache it shows the error... opmn id=oracle10g:6200 no enabled components for this request Whe