TCP Client/Server Whiteboard - Like Netmeeting - Need advice

I won't get into details of the full project, but one part of the project is a whiteboard-like VI that works similar to the whiteboard in Netmeeting. I created a quick server and client VI to establish a TCP connection to allow the whiteboard to run for everyone. Run the server VI first and then the client VI and the whiteboards will open. Normally you would only have one whiteboard running, but this is a demo to allow the client and server to run on the same computer. Please execute the project to understand what the program does so that you understand the concept.
Now for my problem: I spent a several days designing this portion of my project and it is fairly usable, but the problem is that if you continuously draw on the screen for a long time (maybe 1 minute), the arrays will get rather large and will eventually slow the drawing process to a crawl. In a previous version I would draw to the screen, feedback the picture element, and then clear the array, thinking this would be the most efficient. Unfortunately it seemed to be pretty slow also.
I've only been using Labview for a year, so please forgive me if my code is sloppy or if I did things in a weird way. This is why I am posting this code. I'm really looking for advice on optimizing the code and fixing my main problem.
Attachments:
Whiteboard.zip ‏413 KB

Hi Travis,
Thanks for your reply. I saw your post after I already solved the problem otherwise I would look into your suggestions. I thought I would post the solution here so that this code might help someone in the future.
To recap, I had a problem with a drawing slowdown using two different methods. The first method was to draw to a picture element and then loop this around the main while loop and then draw to the picture element again for every pixel movement captured. Reloading the picture element rapidly was a major drag on the CPU. So the second method I used was to store all pixels movements captured in an array and add another array to the second dimension every time the mouse button lifted. I would draw EVERYTHING in this 2D array everytime I looped around. This meant that the array could get rather large after a very short time and bog down the CPU.
So I realized that I could take the best of both methods mentioned and use a nested while loop inside another while loop. The outer while loop shifts the picture element around and the inner loop will continue to build and redraw only one row of the array until the mouse button is up. At this point I stop the inner loop and pass the picture element around null the arrays for the inner loop. Seems to accomplish everything I needed.
Hope this can help somebody else. The new code is attached
Attachments:
Whiteboard.zip ‏515 KB

Similar Messages

  • TCP Client - Server Prog.

    Hi All,
    I have posted TCP client- server prog. I have trouble in client code. When i'm running the server code on some port and the running the client code on the same port, then client is sending message to server(in this case integers with space like 12 22 23) , the server is receiving the message and adding the sum and sending the sum to client, but when i'm trying to read the stream from server(i.e the sum), i'm getting nothing.........
    please run the code and check.......u can understand well....
    please reply me as soon as possible.
    Thanks
    import java.io.*;
    import java.net.*;
    class TCPAdditionClient
         public static void main(String args[]) throws Exception
         {   Character ans = null;
              String hostname="localhost";
              String sentence;
              String result;
              int port=0;
              if (args.length > 0) {
              try {
              port = Integer.parseInt(args[0]);
              } catch (NumberFormatException e) {
              System.err.println("Argument must be an integer");
              System.exit(1);
              Socket clientSocket = new Socket(hostname,port);
              do
                   System.out.println("Enter the number of integers....");
                   BufferedReader fromUser = new BufferedReader(new InputStreamReader(System.in));
                   sentence = fromUser.readLine();
                   DataOutputStream outToServer = new DataOutputStream(clientSocket.getOutputStream());
                   //System.in.read();
                   outToServer.writeBytes(sentence + '\n');
                   System.out.println("server sends message");
                   BufferedReader fromServer = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
                   System.out.println(fromServer);
                   result = fromServer.readLine();
                   System.out.println("from Server" + result);
                   System.out.println("Do u want to continue y/n");
              }while(! ans.equals("n"));
              clientSocket.close();
    import java.io.*;
    import java.util.*;
    import java.net.*;
    class TCPAdditionServer
         public static void main(String args[]) throws Exception
              String clientSentence;
              int port=0;
              if (args.length > 0) {
              try {
              port = Integer.parseInt(args[0]);
              } catch (NumberFormatException e) {
              System.err.println("Argument must be an integer");
              System.exit(1);
              ServerSocket welcomeSocket = new ServerSocket(port);
              while(true)
                   int sum = 0,total_sum = 0;
                   Socket connectionSocket = welcomeSocket.accept();
                   BufferedReader fromClient = new BufferedReader(new InputStreamReader(connectionSocket.getInputStream()));
                   DataOutputStream outToClient = new DataOutputStream(connectionSocket.getOutputStream());
                   clientSentence = fromClient.readLine();
                   System.out.println(clientSentence);
                   String[] result = clientSentence.split(" ");
                   for (int x=0; x<result.length; x++)
                        sum = Integer.parseInt(result[x]);
                        total_sum = sum + total_sum;
                        System.out.println(total_sum);
                   String sendData = "from the server" + "sum :" + total_sum;
                   System.out.println(sendData);
                   outToClient.writeBytes(sendData);
    ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    can u explain it http://www.catb.org/~esr/faqs/smart-questions.html#writewell
    How To Ask Questions The Smart Way
    Eric Steven Raymond
    Rick Moen
    Write in clear, grammatical, correctly-spelled language
    We've found by experience that people who are careless and sloppy writers are usually also careless and sloppy at thinking and coding (often enough to bet on, anyway). Answering questions for careless and sloppy thinkers is not rewarding; we'd rather spend our time elsewhere.
    So expressing your question clearly and well is important. If you can't be bothered to do that, we can't be bothered to pay attention. Spend the extra effort to polish your language. It doesn't have to be stiff or formal - in fact, hacker culture values informal, slangy and humorous language used with precision. But it has to be precise; there has to be some indication that you're thinking and paying attention.
    Spell, punctuate, and capitalize correctly. Don't confuse "its" with "it's", "loose" with "lose", or "discrete" with "discreet". Don't TYPE IN ALL CAPS; this is read as shouting and considered rude. (All-smalls is only slightly less annoying, as it's difficult to read. Alan Cox can get away with it, but you can't.)
    More generally, if you write like a semi-literate b o o b you will very likely be ignored. So don't use instant-messaging shortcuts. Spelling "you" as "u" makes you look like a semi-literate b o o b to save two entire keystrokes.

  • Help with MIDlets - TCP client server program

    Hi I am new to using MIDlets, and I wanted to create a simple TCP client server program.. I found a tutorial in J2me forums and I am able to send a single message from server(PC) to client(Phonemulator) and from client to server. But I want to send a stream of messages to the server. Here is my program and I am stuck in the last step wher i want to send lot of messages to server. Here is my program, Could any one of u tell me how to do it? Or where am i going wrong in thsi pgm?
    Code:
    import java.io.InputStream;
    import java.io.IOException;
    import java.io.OutputStream;
    import javax.microedition.io.Connector;
    import javax.microedition.io.SocketConnection;
    import javax.microedition.io.StreamConnection;
    import javax.microedition.lcdui.Alert;
    import javax.microedition.lcdui.AlertType;
    import javax.microedition.lcdui.Command;
    import javax.microedition.lcdui.CommandListener;
    import javax.microedition.lcdui.Display;
    import javax.microedition.lcdui.Displayable;
    import javax.microedition.lcdui.Form;
    import javax.microedition.lcdui.StringItem;
    import javax.microedition.lcdui.TextField;
    import javax.microedition.midlet.MIDlet;
    import javax.microedition.midlet.MIDletStateChangeExcepti on;
    public class SocketMIDlet extends MIDlet
    implements CommandListener, Runnable {
    private Display display;
    private Form addressForm;
    private Form connectForm;
    private Form displayForm;
    private TextField serverName;
    private TextField serverPort;
    private StringItem messageLabel;
    private StringItem errorLabel;
    private Command okCommand;
    private Command exitCommand;
    private Command backCommand;
    protected void startApp() throws MIDletStateChangeException {
    if (display == null) {
    initialize();
    display.setCurrent(addressForm);
    protected void pauseApp() {
    protected void destroyApp(boolean unconditional)
    throws MIDletStateChangeException {
    public void commandAction(Command cmd, Displayable d) {
    if (cmd == okCommand) {
    Thread t = new Thread(this);
    t.start();
    display.setCurrent(connectForm);
    } else if (cmd == backCommand) {
    display.setCurrent(addressForm);
    } else if (cmd == exitCommand) {
    try {
    destroyApp(true);
    } catch (MIDletStateChangeException ex) {
    notifyDestroyed();
    public void run() {
    InputStream is = null;
    OutputStream os = null;
    StreamConnection socket = null;
    try {
    String server = serverName.getString();
    String port = serverPort.getString();
    String name = "socket://" + server + ":" + port;
    socket = (StreamConnection)Connector.open(name, Connector.READ_WRITE);
    } catch (Exception ex) {
    Alert alert = new Alert("Invalid Address",
    "The supplied address is invalid\n" +
    "Please correct it and try again.", null,
    AlertType.ERROR);
    alert.setTimeout(Alert.FOREVER);
    display.setCurrent(alert, addressForm);
    return;
    try {
    // Send a message to the server
    String request = "Hello\n\n";
    //StringBuffer b = new StringBuffer();
    os = socket.openOutputStream();
    //for (int i=0;i<10;i++)
    os.write(request.getBytes());
    os.close();
    // Read the server's reply, up to a maximum
    // of 128 bytes.
    is = socket.openInputStream();
    final int MAX_LENGTH = 128;
    byte[] buf = new byte[MAX_LENGTH];
    int total = 0;
    while (total<=5)
    int count = is.read(buf, total, MAX_LENGTH - total);
    if (count < 0)
    break;
    total += count;
    is.close();
    String reply = new String(buf, 0, total);
    messageLabel.setText(reply);
    socket.close();
    display.setCurrent(displayForm);
    } catch (IOException ex) {
    Alert alert = new Alert("I/O Error",
    "An error occurred while communicating with the server.",
    null, AlertType.ERROR);
    alert.setTimeout(Alert.FOREVER);
    display.setCurrent(alert, addressForm);
    return;
    } finally {
    // Close open streams and the socket
    try {
    if (is != null) {
    is.close();
    is = null;
    } catch (IOException ex1) {
    try {
    if (os != null) {
    os.close();
    os = null;
    } catch (IOException ex1) {
    try {
    if (socket != null) {
    socket.close();
    socket = null;
    } catch (IOException ex1) {
    private void initialize() {
    display = Display.getDisplay(this);
    // Commands
    exitCommand = new Command("Exit", Command.EXIT, 0);
    okCommand = new Command("OK", Command.OK, 0);
    backCommand = new Command("Back", Command.BACK, 0);
    // The address form
    addressForm = new Form("Socket Client");
    serverName = new TextField("Server name:", "", 256, TextField.ANY);
    serverPort = new TextField("Server port:", "", 8, TextField.NUMERIC);
    addressForm.append(serverName);
    addressForm.append(serverPort);
    addressForm.addCommand(okCommand);
    addressForm.addCommand(exitCommand);
    addressForm.setCommandListener(this);
    // The connect form
    connectForm = new Form("Connecting");
    messageLabel = new StringItem(null, "Connecting...\nPlease wait.");
    connectForm.append(messageLabel);
    connectForm.addCommand(backCommand);
    connectForm.setCommandListener(this);
    // The display form
    displayForm = new Form("Server Reply");
    messageLabel = new StringItem(null, null);
    displayForm.append(messageLabel);
    displayForm.addCommand(backCommand);
    displayForm.setCommandListener(this);

    Hello all,
    I was wondering if someone found a solution to this..I would really appreciate it if u could post one...Thanks a lot..Cheerz

  • TCP client server sample

    All,
    This may not really be a LabWindows/CVI question but I'm really stuck on what should be easy to
    solve. The brain trust here on the forums has always been helpful so I'll try to explain.
    The project:
    Get LabWindows/CVI code talking to a muRata SN8200 embedded WiFi module.
    The setup:
    (running Labwindows/CVI 2009)
    Computer 1 -- (with a wireless NiC) running simple demo TCP server program provided by muRata.
    Computer 2 -- USB connection (virtual COM port) with simple program (also provided by muRata) that talks to the SN8200 embedded WiFi module.  This code along with the module creates a simple TCP client.
    Whats working:
    I can successfuly get the Computer 2 client connected to and talking to the Computer 1 server. (using the muRata supplied code)
    I can also run the LabWindows/CVI sample code from (\CVI2009\samples\tcp), server on computer 1 & client on computer 2 and they talk with no problems.
    (I'm using the same IP addresses and port numbers in all cases)
    Whats NOT working:
    Run the CVI server program on computer 1.
    I cannot get the muRata client program  to connect to the CVI server.
    I also tried get the CVI client program to connect to the muRata server.  No luck that way either. The CVI client sample program trys connect, and this function call:
    ConnectToTCPServer (&g_hconversation, portNum, tempBuf, ClientTCPCB, NULL, 5000 );
    returns with a timeout error code (-11).
    What I need:
    Some ideas on how to get this working.
    Is there something unique about the LabWindows/CVI sample client/server demo code that would make them incompatible with the muRata code?
    Can you think of some ways I can debug this further?  I feel like I'm kind of running blind.
    What else can I look at?
    For those that have read this far, thanks much and any ideas or comments will be appreciated,
    Kirk

    Humphrey,
    First,
    I just figured out what the problem is:
    When I was trying to use the CVI sample server I was entering the wrong port number.
    The reason I entered the wrong port was because the hard-coded port number in the muRata demo code was displayed in hex as 0x9069. ( I converted this to decimal and entered it into the CVI sample server code) The correct port number was 0x6990.  (upper and lower bytes swapped)  Arrgh!
    I found the problem by using the netstat command line utility to display the connections and noted that the port being used was not 0x9069.  It is really a problem with the muRata eval kit demo code.
    Second,
    Humphrey you are right about the CVI sample code not handling all the muRata commands for the client end of the connection that communicates with the SN8200 module.  For my test I was using the muRata code for that "end".
    The server end is simple and the CVI sample is adequate and is now working.
    Thank you to all who took the time to browse my questions,
    Kirk

  • TCP Client Server - how to set timeout and bandwidth option

    Hi Friends,
    I am writing a simple TCP based client-server app and I would like the connection to be dropped after a certain time of inactivity and also I would like to control the connection's bandwidth. I would appreciate if someone can throw some pointers as to how this can be done.
    I have tried this so far, for Timeout I am trying to do this:
    sock.setSoTimeout(10000);But I think this is not the right way as this will disconnect the server from all client connections I guess. I think the better way would be to write a timer or something for each connection but I don't know how...
    Any help?

    Micks80 wrote:
    Hi Friends,
    I am writing a simple TCP based client-server app and I would like the connection to be dropped after a certain time of inactivity and also I would like to control the connection's bandwidth. I would appreciate if someone can throw some pointers as to how this can be done.
    I have tried this so far, for Timeout I am trying to do this:
    sock.setSoTimeout(10000);But I think this is not the right way as this will disconnect the server from all client connections I guess.Wrong in a couple of ways.
    1) That doesn`t disconnect anything. It causes a read that reaches that time in blocking to be unblocked and an exception (java.net.SocketTimeoutException) is thrown. The Socket is still just fine and can be used (all other things being equal). At any rate you then decide what you want to do after a timeout. One possibility is to close the socket because to you that timeout means it is abandoned.
    2) setSoTimeout of ServerSocket applies to the accept* method. setSoTimeout of Socket applies to reads from that sockets input stream. Neither of those apply anything to all connections.
    I think the better way would be to write a timer or something for each connection No setSoTimeout is correct. You will also then need to actually attempt to read something for that timeout exception to ever be thrown.
    As far as the bandwidth question goes, you will need to define your goals better. Please do not just restate "control bandwidth" because that is not actually a very specific goal. Do you want to limnit the bandwidth used at one time (tricky) or do you want to limit the total bandwidth used. Either way requires some work but they are different things.

  • Client-Server office discussion. Need a pattern ?

    Hello all,
    1. We are new in network programming, so please forgive us for such a dum question.
    In our last project we were requested to write a very simple java server which would handle some "Task process" state by recieving commands "start,stop,getStatus".
    Although we were able to easily write the code, we had a doubt that created a team discussion.
    Were should the socket connection be stablished ?
    Some of us stated that the "Constructor" should establish the connection to the socket, as the "Server" can not exists if it is not listening to a port.
    Some others stated that a "Run/Start" method should do this.
    Obviouly either way works, yet I'm hopping that the Gurus here can help us determine the right answer.
    2. I read about MVC pattern but I can't find a link to a well explained "Client-Server" pattern. Does anyone know a good place to find patterns ?
    Thanks in advanced for you help !!!
    It's great to be part of this community.
    Thanks..

    Hello all,
    1. We are new in network programming, so please
    forgive us for such a dum question.
    In our last project we were requested to write a very
    simple java server which would handle some "Task
    process" state by recieving commands
    "start,stop,getStatus".
    Although we were able to easily write the code, we
    had a doubt that created a team discussion.
    Were should the socket connection be stablished ?
    Some of us stated that the "Constructor" should
    establish the connection to the socket, as the
    "Server" can not exists if it is not listening to a
    port.
    Some others stated that a "Run/Start" method should
    do this.
    Obviouly either way works, yet I'm hopping that the
    Gurus here can help us determine the right answer.
    Why not use a Servlet? That having been said, if I did want to re-invent the wheel, I would add startListening() and stopListening() methods to the class that manages the ServerSocket. You can always force a JVM exit, but why not at least provide methods for callers that want to end gracefully?
    2. I read about MVC pattern but I can't find a link
    to a well explained "Client-Server" pattern. Does
    anyone know a good place to find patterns ?
    Thanks in advanced for you help !!!
    It's great to be part of this community.
    Thanks..Do a Google search on writing a multi-threaded server. A number of patterns could apply. Client-server is really an architecture, not a pattern. Any number of patterns (or anti-patterns) could actually implement it.
    - Saish

  • TCP client server

    hi,
    how do i do this:
    Create a Server Program in TCP
    Create a file with some data.
    Create a Client Program in TCP
    Establish a connection with the server
    On establishment, the server should read the data from the file and write onto the socket of the client.
    The client has to read the data from the socket and write onto a different file.

    hi,
    this is the server code that i have.
    import java.io.*;
    import java.net.*;
    public class fileServer {
    public fileServer() {
    int i=1;
    try {
    ServerSocket s = new ServerSocket(5000);
    System.out.println("Server Started...");
    Socket incoming = s.accept();
    Thread t = new ThreadedServer(incoming, i);
    i++;
    t.start();
    }catch(Exception e){
    System.out.println("Error: "+e);
    public static void main(String args[]){
    new fileServer();
    class ThreadedServer extends Thread{
    int n;
    Socket fileSocket;
    int count;
    public ThreadedServer(Socket i, int c){
    fileSocket = i;
    count = c;
    public void run(){
    BufferedReader buffRead = null;
    OutputStream os;
    try{
    File f = new File("file1.txt");
    FileInputStream fis = new FileInputStream(f);
    os = fileSocket.getOutputStream();
    int buffSize = 4096;
    byte[] buff = new byte[buffSize];
    int count = 0;
    while((count = fis.read(buff))>= 0) {
    os.write(buff,0,(int)count);
    System.out.println(os);
    fis.close();
    os.close();
    }catch(IOException ioe) {
    System.out.println("this is a IOException"+ioe.getMessage());
    This is the client code that i have:
    import java.io.*;
    import java.net.*;
    public class fileClient{
    public static void main(String args[]){
    Socket clientSocket;
    PrintStream out = null;
    BufferedReader in = null;
    try{
    clientSocket = new Socket("10.45.2.34",5000);
    System.out.println("connection established");
    out = new PrintStream(clientSocket.getOutputStream());
    in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
    String text = in.readLine();
    System.out.println(text);
    in.close();
    out.close();
    }catch (UnknownHostException e){
    System.err.println("unidentified hostname");
    System.exit(1);
    }catch(IOException ioe) {
    System.err.println("couldnt get I/O");
    System.exit(1);
    The above code works fine,but the final step i.e the client has to read the data from the socket and write onto a different file is not performed.
    So how do i proceed from here.

  • Adding Windows server to my company Need Advice

    Hello,
    I own and operate hostoople.com. I have just added windows servers and want to keep my servers on my racks in Dallas Texas.  I dont want to spend 800-1k upfront for a license for my windows servers. Is there any one i can lease the license thru month
    to month then purchase it?  And in house financing programs?I want to expand this product line out .
    Any help would be great, thank you Nick Anderson

    This depends on what's doing the routing for your vlans. Do you have a L3 switch, or are you using subinterfaces on the router? By default, all vlans can route between all other vlans, so technically you should be able to add the server to whichever vlan you want. You didn't tell us where the clients are in relation to the server. Are they on the other side of the router? Is the server on the same side as the clients? If the clients are connected to one of the 3 switches along with the router, then you shouldn't have any problems. Make the switchport that the server connects to an access port to the vlan that you want it on. Then verify that the vlan is on the trunk port between switches.
    HTH,
    John

  • Handle Received data of Multiple TCP clients on TCP Server by displaying them into Datagrid

    Hello All,
    I have developed a C# based TCP server GUI application which is accepting the data from multiple TCP clients on TCP server.
    The data i am receiving from TCP clients is a 32 bit data. In my application multiple TCP client data goes like this:
    00012331100025123000124510321562
    01112563110002512456012451032125 and so on...
    Now i want those data of the TCP clients to be parsed into 4 bits first and display it in 8 columns (32/4=8) of (say) datagrid as each 4 bit represents some characteristics of the TCP client. The same thing
    should work for next TCP client on second row of datagrid.            
    Can you give me some suggestion or an example how to go about this? Any help would be appreciated.
     Thank you in advance.
    Here is my code for receiving data from multiple TCP clients.
    void m_Terminal_MessageRecived(Socket socket, byte[] buffer)
    string message = ConvertBytesToString(buffer, buffer.Length);
    PublishMessage(listMessages, string.Format("Sockets: {0}", message));
    // Send Echo
    // m_ServerTerminal.DistributeMessage(buffer);
    private string ConvertBytesToString(byte[] bytes, int iRx)
    char[] chars = new char[iRx + 1];
    System.Text.Decoder d = System.Text.Encoding.UTF8.GetDecoder();
    d.GetChars(bytes, 0, iRx, chars, 0);
    string szData = new string(chars);
    return szData;

    Now i want those data of the TCP clients to be parsed into 4 bits first and display it in 8 columns (32/4=8) of (say) datagrid as each 4 bit represents some characteristics of the TCP client. The same thing
    should work for next TCP client on second row of datagrid
    If mean it's a Windows Forms application and you want to display those bits in a DataGridView control, then please see these threads:
    Add row to datagridview
    Programmatically add new row to DataGridView
    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.
    Click
    HERE to participate the survey.

  • Client/server/web application

    My application will be deployed as client/server application and as well as web application. An database is used to keep the persistent data.
    For the client/server environment, I will need client tier, application server tier, and the database tier. For the web applicaiton, I will need web interface, web server, and the database tier.
    My question is that since the application will be deployed as both client/server application and web application, how to leverage the components, so the application server and the web server has less code duplication.
    Is there any guideline for designing such an architecture?
    The application uses J2SE, and Tomcat is the servlet engine.
    Thanks for any input /danclemson

    Your business logic should be written so that it can used from anywhere. Command line, GUI, webapp, it's irrelevant. Likewise with the db layer, so those will be exactly the same. Then you just put whatever front end you want on it. Now, if you're talking about having the same server used for both at the same time, that's a different question. But it sounds like you're asking about code.

  • Client/server security protection

    I want my server application to only accept incoming connections from certain ips. I know there is a SecurityManager class where I can write my own class to extend this, but the function acceptConnect takes ip and port. What if I don't care what port the client is on? I mean obviously if a client connects to the server they will be connected on a local port.
    Anyhow, is there another level of protection I can have between my client/server application like a password of some sort? Do I need a security manager for something like this?

    You have to be listening for connections on some particular port, you can't just accept connections any old where (AFAIK). So, the IP/port number combo should work for you.

  • PDK and Client/Server

    Hello,
    is it possible to create a portlet for a normal client/server application like MS Word oder PowerPoint to be displayed/used in Oracle Portal? Does the PDK solve the problem or do i need web-enabled versions of these programms?
    If it is possible do so, could you please give me a shot discription of how to do it.
    greeting
    Thomas

    GUI based applications are good but do you think that will it be maintainable and portable?.. Some of the GUI based applications are build on higher Java like 1.5.. i Presume you have the latest and other workstation have only 1.4 or 1.3, this can be n issue on GUI based applications especially on installation on each workstation.

  • Help needed on TCP/IP Multi-port Client-Server

    Hi all, I am trying to develop a client-server application to stream some data over a few random port numbers (defined by myself) to stream data over to the TCP server (i.e another computer) in LabVIEW. So far, I have created my application using the NI examples for "Simple Data Client + Server" and it works fine. I also understand that the "TCP Listen" VI is only able to listen for 1 TCP connection only and a way around this is to use queueing idea to receive & process the incoming data.The downside to the idea is that the "base port" (i.e initial port) needs to be the same (on every TCP client) with the TCP Server and it is not fit for the purpose I intended.
    Basically on the TCP server side, i need to chart/monitor the data on different port numbers that is being streamed real-time from the one TCP client computer. Is this possible in LabVIEW?
    Can anyone (incl. NI gurus) advise and point me in the right direction?
    *lost*
    Solved!
    Go to Solution.

    Hi
        http://zone.ni.com/devzone/cda/epd/p/id/2739 Here you can download that component.But you can also use TCP icons which is available in Data Commmunications>Protocals>TCp for communication and to read and write data use variant to flattened string. I have attached a small example where i will transfer a constant string to the host PC to check the link between client and the server. Hope this helps you.
    Attachments:
    TCP Comm.zip ‏47 KB

  • Async tcp client and server. How can I determine that the client or the server is no longer available?

    Hello. I would like to write async tcp client and server. I wrote this code but a have a problem, when I call the disconnect method on client or stop method on server. I can't identify that the client or the server is no longer connected.
    I thought I will get an exception if the client or the server is not available but this is not happening.
    private async void Process()
    try
    while (true)
    var data = await this.Receive();
    this.NewMessage.SafeInvoke(Encoding.ASCII.GetString(data));
    catch (Exception exception)
    How can I determine that the client or the server is no longer available?
    Server
    public class Server
    private readonly Dictionary<IPEndPoint, TcpClient> clients = new Dictionary<IPEndPoint, TcpClient>();
    private readonly List<CancellationTokenSource> cancellationTokens = new List<CancellationTokenSource>();
    private TcpListener tcpListener;
    private bool isStarted;
    public event Action<string> NewMessage;
    public async Task Start(int port)
    this.tcpListener = TcpListener.Create(port);
    this.tcpListener.Start();
    this.isStarted = true;
    while (this.isStarted)
    var tcpClient = await this.tcpListener.AcceptTcpClientAsync();
    var cts = new CancellationTokenSource();
    this.cancellationTokens.Add(cts);
    await Task.Factory.StartNew(() => this.Process(cts.Token, tcpClient), cts.Token, TaskCreationOptions.LongRunning, TaskScheduler.Default);
    public void Stop()
    this.isStarted = false;
    foreach (var cancellationTokenSource in this.cancellationTokens)
    cancellationTokenSource.Cancel();
    foreach (var tcpClient in this.clients.Values)
    tcpClient.GetStream().Close();
    tcpClient.Close();
    this.clients.Clear();
    public async Task SendMessage(string message, IPEndPoint endPoint)
    try
    var tcpClient = this.clients[endPoint];
    await this.Send(tcpClient.GetStream(), Encoding.ASCII.GetBytes(message));
    catch (Exception exception)
    private async Task Process(CancellationToken cancellationToken, TcpClient tcpClient)
    try
    var stream = tcpClient.GetStream();
    this.clients.Add((IPEndPoint)tcpClient.Client.RemoteEndPoint, tcpClient);
    while (!cancellationToken.IsCancellationRequested)
    var data = await this.Receive(stream);
    this.NewMessage.SafeInvoke(Encoding.ASCII.GetString(data));
    catch (Exception exception)
    private async Task Send(NetworkStream stream, byte[] buf)
    await stream.WriteAsync(BitConverter.GetBytes(buf.Length), 0, 4);
    await stream.WriteAsync(buf, 0, buf.Length);
    private async Task<byte[]> Receive(NetworkStream stream)
    var lengthBytes = new byte[4];
    await stream.ReadAsync(lengthBytes, 0, 4);
    var length = BitConverter.ToInt32(lengthBytes, 0);
    var buf = new byte[length];
    await stream.ReadAsync(buf, 0, buf.Length);
    return buf;
    Client
    public class Client
    private TcpClient tcpClient;
    private NetworkStream stream;
    public event Action<string> NewMessage;
    public async void Connect(string host, int port)
    try
    this.tcpClient = new TcpClient();
    await this.tcpClient.ConnectAsync(host, port);
    this.stream = this.tcpClient.GetStream();
    this.Process();
    catch (Exception exception)
    public void Disconnect()
    try
    this.stream.Close();
    this.tcpClient.Close();
    catch (Exception exception)
    public async void SendMessage(string message)
    try
    await this.Send(Encoding.ASCII.GetBytes(message));
    catch (Exception exception)
    private async void Process()
    try
    while (true)
    var data = await this.Receive();
    this.NewMessage.SafeInvoke(Encoding.ASCII.GetString(data));
    catch (Exception exception)
    private async Task Send(byte[] buf)
    await this.stream.WriteAsync(BitConverter.GetBytes(buf.Length), 0, 4);
    await this.stream.WriteAsync(buf, 0, buf.Length);
    private async Task<byte[]> Receive()
    var lengthBytes = new byte[4];
    await this.stream.ReadAsync(lengthBytes, 0, 4);
    var length = BitConverter.ToInt32(lengthBytes, 0);
    var buf = new byte[length];
    await this.stream.ReadAsync(buf, 0, buf.Length);
    return buf;

    Hi,
    Have you debug these two applications? Does it go into the catch exception block when you close the client or the server?
    According to my test, it will throw an exception when the client or the server is closed, just log the exception message in the catch block and then you'll get it:
    private async void Process()
    try
    while (true)
    var data = await this.Receive();
    this.NewMessage.Invoke(Encoding.ASCII.GetString(data));
    catch (Exception exception)
    Console.WriteLine(exception.Message);
    Unable to read data from the transport connection: An existing   connection was forcibly closed by the remote host.
    By the way, I don't know what the SafeInvoke method is, it may be an extension method, right? I used Invoke instead to test it.
    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.
    Click
    HERE to participate the survey.

  • Need help in desigining Client/Server Application using Java

    Hi,
    I am new to Java and no sooner that I started studing it I have been given a project - client server java Application that allows a user to do a property search based on critiras (eg location, price) and display the results. I am stuck because I don't know where I need to start. Have to use IDE (Netbeans or Eclipse) but not sure about dev frameworks.
    Can someone give me an outline of what I should do / where I should start? What will be the best solution?
    Thanks in adance

    http://java.sun.com/docs/books/tutorial/networking/index.html
    That's Sun's networking tutorial series. Live it, learn it, love it. You'll need to decide if you want to use connected sockets or datagrams. You'll need details like, can multiple clients connect simultaneously?
    The tutorials are the first step though.

Maybe you are looking for

  • Cropping images in 45 degrees

    Hi forum, I have a problem: I've turned a few images on a 45 degree angle, but seeing that these images are fairly big, they now overlap each other on the facing pages set up. It's a problem I cannot solve through layers, so: How do I crop the images

  • Date Functions( first day of a month that is 3 months from now....)

    I have recently written my first stored procedure. Its rather a bunch of SQL statements. I had to hard code lot of dates. most of them are first day of the current monthe or last day of current month etc. I thot of parametrizing all the dates, but if

  • Export Import 9i

    Hi My exp parfile looks like the following and I did export as user "abc" buffer=3145728 direct=y compress=n consistent=y constraints=y feedback=1000000 file=a.dmp grants=y indexes=y log=a.log owner=abc recordlength=65535 rows=n And import parfile lo

  • How does on get Aperture to rename edited versions of a file

    When I edit a photo, I would like Aperture to apend the edited file with a number, as in the way Lightroom does, how do I accomplish this?  The reason for this is to look at the name and know which file is which in the editing process.  If Aperture h

  • I am having trouble with my FaceTime

    I am having trouble with my FaceTime