How can a VI be both server and client?

Hi, 
I'm new in LabView and I'm trying to build a server and client VI using TCP/IP that runs in two computers. in my program I need both server and client VIs to communicate with each other which means I need both VIs to be server and client. I've tried using a case structure but it doesnt work. The only thing I achieved is a normal server/client system where the server sends a request and the client responses.But i need the client to send requests too.i have attached my VIs to this post.I would appriciate it if someone could help with this problem. 
Thanks in advanced. 
Rambaldi.
Solved!
Go to Solution.
Attachments:
Server-Client.zip ‏41 KB

Do you really need a client and server on each PC? If you simply need that two to talk to each other they can once the client connects to the server. In most cases you only need one server.
What Steve said about the not using the same port only applies to two servers on the same machine. A client must use the port the server is listening to and if the client and the server are on the same machine then they will both use the same port. However, only ONE of them is accepting waiting for connections on that port.
In the code you posted you actually swapped the names. What you call the client is actually the server code and vise versa. In networking a server is an application that listens to an assigned port, accepts connections on that port and provides whatever services it has implemented. A client is an application that establishs a connection to a server. Once a connection is established the two applications can communicate in both directions. The applications themselves will define how the conversation should progress and whether it is a one way conversation or a two way conversation. You don't specify what you are trying to accomplish but I suspect you only need a single server.
In TCP, every connection is defined by the source and destination IP addresses and the source and destination ports. The server uses a known port (FTP is port 21, HTTP is 80, telnet is 23, or some custom port in the user space beyonds the reserved ports) to listen for connections. The client will use the well known port of teh server and generally picks a random port for its port number. The LabVIEW VIs do this automatically. This is how a server and a client on the same computer can use the same port number. Two servers however cannot. The server application can spawn a child task allowing it to service multiple connections at one time though. Each connection will be unique though since the client's port number, address or both will change for each connection.
OK, end of networking 101.
Can you describe in a bit more detail what exactly you want to accomplish. Given that I could probably provide you with more information for your application.
Mark Yedinak
"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot

Similar Messages

  • Try to use one comupter as both server and client

    Hello, everyone, I am just trying to use my own computer as both server and client to test some codes about networking. For example, use the sample code in java tutorial which is used to test Echo server(code is listed below). Is there anything I have to do to set my computer, such as set my hostname or something like that?
    I am a pure newbie. And the purpose of this question is to test some code including socket on one PC without connect to internet.
    I have tried to change the name "taranis" in the following code to the computer name of my own PC, but it doesn't work, and said: Couldn't get I/O for the connection to: (my computer name).
    import java.io.*;
    import java.net.*;
    public class EchoClient {
    public static void main(String[] args) throws IOException {
    Socket echoSocket = null;
    PrintWriter out = null;
    BufferedReader in = null;
    try {
    echoSocket = new Socket("taranis", 7);
    out = new PrintWriter(echoSocket.getOutputStream(), true);
    in = new BufferedReader(new InputStreamReader(
    echoSocket.getInputStream()));
    } catch (UnknownHostException e) {
    System.err.println("Don't know about host: taranis.");
    System.exit(1);
    } catch (IOException e) {
    System.err.println("Couldn't get I/O for "
    + "the connection to: taranis.");
    System.exit(1);
         BufferedReader stdIn = new BufferedReader(
    new InputStreamReader(System.in));
         String userInput;
         while ((userInput = stdIn.readLine()) != null) {
         out.println(userInput);
         System.out.println("echo: " + in.readLine());
         out.close();
         in.close();
         stdIn.close();
         echoSocket.close();

    Did you write the EchoServer and start it on your
    machine, listening on port 7?
    You can have the client and server running on the same
    machine or different machines, but they have to be
    separate pieces of software.
    Write a separate EchoServer class that starts up and
    listens on that port. Then start the EchoClient and
    make the connection.
    %yeah, I didn't wrote the EchoServer class. But I thought it is automaticly included and therefore has run once I start my computer.
    If I write a EchoServer class, then how should I set the host name of the EchoClient, just simply change "taranis" to my computer name (change "echoSocket = new Socket("taranis", 7);" to echoSocket = new Socket("(my comptuer name)", 7);"?

  • Comprised of both server and client components

    Hello all
    We all consult an open source project and download freely the source code and the documentation for the server as a tarball. The well known open source project is Paragent which its platform is comprised of both server and client components written in Lisp, C++ and Java. just take a look and drop your suggestions.
    Thanks for any help,
    Bmora96

    Huh?

  • HT204408 How can I sign into both iMessages and FaceTime?

    I somehow lost connection with both iMessages and FaceTime on my iMac and now unable to sign in.  I am able to access both the App Store and iTunes Store with my Apple ID and password.  I went through the steps suggested in the help section (TS3970) and all appears fine.  I am operating on a iMac running OS X Yosemite version10.10.2  I do not experience any problems on my IOS devices (IOS 8) running iMessages and FaceTime if this means anything.

    I of course already checked and I also checked iTunes, where else can I check?

  • JAX-RPC: Web service where both server /and/ client are services?

    I'm considering a two-way Web service in an application that I'm designing and would appreciate any insight from prior experience.
    This will be a standard client-server application, where the server broadcasts messages and the client, in turn, can request further information about the messages that it receives (think RSS-style updates, but with more interaction). [strong]However[strong], instead of having the client poll the server for new messages, I'd like to have the client register itself with the server as a message listener. The server is currently implemented as a Web service on port X. I'd like the client to register itself with the server, and then receive messages on port Y.
    I'm considering a design like the following (note the directions of the inheritance arrows):
    ( Server class )  --<-- ( RemoteServerImpl class ) -->-- / RemoteServer interface /
           |
    ( Listener class ) --<-- ( RemoteListenerImpl class ) -->-- / RemoteListener interface /Some considerations:
    * In both cases, the client and server are broken out into an interface and two classes. The non-Remote classes implement all of the functionality. The RemoteX interfaces declare the methods that will be exposed via RPC, and the RemoteXImpl classes are empty subclasses of the non-Remote classes.
    * In order to register itself with the Server, the Listener must be passed in as a method parameter, and thus conform to the JAX-RPC specification for value types. However, value types can't implement java.rmi.Remote.
    * Only the Server and Listener know anything about each other.
    * This application can be run either remotely or locally, depending on how the Server and Listener are instantiated. For the latter, they're instantiated directly and the listener is registered with the Server. For the latter, the RemoteX interfaces will point to the service stubs.
    * I don't see an easy way to allow both the Server and the Listener to have references to each other (at least now without some casting magic), since one of them will have to conform to the value type specification, which requires that all of its fields must be valid JAX-RPC types.
    I've got the Server portions implemented and working, and am now going to turn to the Listener stuff. Can anybody see a fundamental problem with this design, or can suggest something better?

    Hi There,
    Because web services are fundamentally a Services-oriented architecture, and not an Object-oriented one, you are unable to pass objects by reference (only by value) hence the design decision to not allow rmi.Remote objects to be sent across the wire. The best way would be to abstract an object which does itself not represent a server, but a route to a server (lets call it ServerPointer). This must contain address, port, service info, etc.
    Now, in your Server class, create a factory method which takes a ServerPointer, and returns a reference to a
    remote server, e.g. protected Server createServer( ServerPointer p ) (using the necessary APIs to get such a reference)
    Hope this helps...

  • How can I format for both Mac and PC and keep software updated?

    I have a dilemma. I need to be able to have the iPod formatted for use with both a Macintosh and PC so I can use it as a hard disk on both Operating Systems. The dilemma? I will be "Administering" the iPod and iTunes Music Library at home on a Macintosh.
    How do I update the iPod software as new updates become available on an iPod formatted for PC? The thing to know is that I don't have the option to update it on a PC as the only PCs I have access to are at work and I'm not allowed to install iTunes.
    Any ideas?

    You cannot format the iPod for a PC outside of iTunes on a PC while retaining the capability to use the iPod as a music player. If you can't install any software on the work PCs, your best solution may be to use an USB flash drive for transferring files and leave the iPod in the Mac format.
    (25091)

  • How can a component generate both stylesheet and HTML code?

    Hi All,
    I've the following problem. My team is working on several "complex" components which provide a rich client-side behavior (via javascript and css). The components are in charge of generating the following:
    + Stylesheet (linked or inline)
    + Javascript via external libraries
    + HTML code
    The problem comes from the fact that the CSS must be generated between the <HEAD> and </HEAD> tags (according to the HTML spec). Obviously, the rest of the code (javascript and HTML) is generated somewhere else on the page, and this is the problem.
    Any ideas on how to solve this?
    I've been thinking about a pre-process phase that would call every components to render the Css, but it requires substancial changes to JSF... Any help is greatly appreciated
    Thanks in advance,
    Stephane
    http://www.otrix.com

    Thanks for the reply but in my case I absolutely need to generate an addhoc css such as:
    <style type="css/....>
    .name 1 {position: absolute; visibility: hidden... }
    .name 1 {padding: 0 0 0 0;}
    </style>
    What I do is that I spit-out the css first and then generate the HTML. It works fine in IE but I really wanted to be conform to the HTML spec which says that a STYLE tag should be located in the <HEAD> tag. I guess it's probably too much work just to be compliant with the spec....
    Thanks again,
    Stephane

  • Where can one fine TCP socet server and client example VI's for Labview 6.0

    We've inherited an older system containing two PXI systems and one PC.  The Labview -6.0 programs running on the three systems need to be rewritten from ground zero.
    In hopes of saving a great amount of time, I am looking for a couple of TCP socket VI's that can be used to set up communications between the applications.  There doesn't appear to be a backwards compatibility from examples found in newer versions of Labview.
    Thanks,
    KGTang

    kgtang wrote:
    We've inherited an older system containing two PXI systems and one PC.  The Labview -6.0 programs running on the three systems need to be rewritten from ground zero.
    In hopes of saving a great amount of time, I am looking for a couple of TCP socket VI's that can be used to set up communications between the applications.  There doesn't appear to be a backwards compatibility from examples found in newer versions of Labview. 
    Why backwards compatibility?
    Look in examples/comm/tcpex.llb. Those examples are still mostly unchanged in the newer LabVIEW versions too.
    Rolf Kalbermatter
    Rolf Kalbermatter
    CIT Engineering Netherlands
    a division of Test & Measurement Solutions

  • MultiThreaded Server and Client connections query.

    I have written a MultiThreaded Server to accept incoming client requests.
    Multiple clients can connnect to this server and have a conversation.
    I invoke the 'MultiServer' from the command line and then invoke 3 clients
    from the command line.('Client').
    c:> java MultiServer
    c:> java Client
    c:> java Client
    c:> java Client
    All the 3 clients now run in their own thread and send messages
    to the server.
    The problem I am facing is this:
    When client1 connects to the server and sends a message to the server (with the server responding)
    it works fine.Both Server and Client can exchange messages.
    When client2 connects to the server and sends a message and when the server
    responds with a message,the message does NOT go to client2,but goes to Client1
    As Clients have their own thread to run,shouldnt the messages also be delivered to
    individual clients
    Am I missing something?
    My Code
    public class MultiServer {
        public static void main(String[] args) throws IOException {
            ServerSocket serverSocket = null;
            boolean listening = true;
            try {
                serverSocket = new ServerSocket(4444);
                System.out.println("MultiServer listening on Port 4444");
            } catch (IOException e) {
                System.err.println("Could not listen on port: 4444.");
                System.exit(-1);
            // Indefinite Loop.
            while (listening)
             new MultiServerThread(serverSocket.accept()).start();
            serverSocket.close();
    public class MultiServerThread extends Thread {
        private Socket socket = null;
        public MultiServerThread(Socket socket) {
         super("MultiServerThread");
         this.socket = socket;
        public void run() {
         try {
             PrintWriter out = new PrintWriter(socket.getOutputStream(), true);
             BufferedReader in = new BufferedReader(
                            new InputStreamReader(
                            socket.getInputStream()));
               BufferedReader stdInFromServer = new BufferedReader(new InputStreamReader(System.in));
            String fromTheClient,fromServer;
               fromServer = "Hi Client,How u doing? ";
            // Send a message from the Server.
               out.println(fromServer);
                while ((fromTheClient = in.readLine()) != null) {
                 if (fromTheClient.equals("ByeServer"))
                 break;
                 // Display message received from Client.
                 System.out.print("Client Response : ");
              System.out.println(fromTheClient);
                 // Input reply from the Server.
                 fromServer = stdInFromServer.readLine();
                 out.println(fromServer);
                 if (fromServer.equals("Bye."))
                    break;
             out.close();
             in.close();
             socket.close();
         } catch (IOException e) {
             e.printStackTrace();
    Client Code
    ===========
    public class Client {
        public static void main(String[] args) throws IOException {
            Socket kkSocket = null;
            PrintWriter out = null;
            BufferedReader in = null;
            try {
                kkSocket = new Socket("localhost", 4444);
                out = new PrintWriter(kkSocket.getOutputStream(), true);
                in = new BufferedReader(new InputStreamReader(kkSocket.getInputStream()));
            } catch (UnknownHostException e) {
                System.err.println("Don't know about host: localhost.");
                System.exit(1);
            } catch (IOException e) {
                System.err.println("Couldn't get I/O for the connection to: localhost.");
                System.exit(1);
            BufferedReader stdIn = new BufferedReader(new InputStreamReader(System.in));
            String fromServer;
            String fromUser;
            while ((fromServer = in.readLine()) != null) {
                System.out.println("Server: " + fromServer);
                if (fromServer.equals("Bye."))
                    break;
                    fromUser = stdIn.readLine();
             if (fromUser != null) {
                    out.println(fromUser);
            out.close();
            in.close();
            stdIn.close();
            kkSocket.close();
    }

    Taking standard input for multiple threads from one console is quite unpredictable. I think the first client thread is waiting for input when you connect the second. You type something into your server window and since the first thread was waiting for input, it takes the input and sends it to client 1.

  • UDP server and client running on same machine

    Hi all,
    I can't get the QuoteServer example to work. I am trying to run both server and client on same machine since I only have one machin available at the moment.
    I am using win xp behind a firewall. Anything that might interfere?
    With some System outs I can see that the server is waiting for request but never getting any...

    Restarted computer and now it works. Are ports locked up if I get an exception in the 'wrong' place?

  • LDAP (Directory service) server and client compatiblw with windows 7

    Hello Experts,
    Earlier we were using Netscape Server 4.0 and Console  in Windows XP for LDAP Integration testing with BRM.
    Now that Windows XP is soon going to be decommissioned and the software is incompatible with windows 7,I am looking for Directory service (both server and client) alternatives compatible with Windows 7.
    Has  anyone tried setting up a Directory service(or LDAP) in windows 7 Operating system ??
    Any help is appreciated. Thank you

    Hello Mr Thio,
    Basic cause for this type of error message is Generally permission issue.If you are using a domain account make sure it is added as local administrator in local machine.
    RK on setup.exe and select run as administrator
    Makes sure you copy installables on local drive and run setup from machine if your are running from CD directly avoid it.
    Below MS link has documented this error please go through the link properly
    http://support.microsoft.com/kb/2799534
    Please mark this reply as the answer or vote as helpful, as appropriate, to make it useful for other readers

  • How can we find the most usage and lowest usage of table in Sql Server by T-SQL

    how can we find the most usage and lowest usage of table in Sql Server by T-SQL
    The table has time stamp column
    StartedOn datetime
    EndedOn datetime

    The Below query has been used , but the textdata column doesnot include the name of the table ServiceLog.
    SELECT
    FROM
    databasename,
    duration
    fn_trace_gettable('F:\Program
    Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\Log\log_148.trc',
    default)
    WHERE
    DATABASENAME='ZTCFUTURE'
    AND TEXTDATA
    IS
    NOT
    NULL
    --AND TEXTDATA LIKE 'SERVICE%'
    order
    by cpu
    desc; 

  • I have 2 icloud accounts how can i see them both on my macbook and iphone

    I have 2 icloud accounts how can I see them both on my macbook and iphone?

    iCloud doesn't have anything to do with texts or phone calls. Those are both tied to your phone number and SIM, not to an iCloud account.

  • My Apple ID and rescue email are reversed. How can I change them both at the same time

    My Apple ID and rescue email are reversed. How can I change them both at the same time?

    I'd already used this standard tool (exhaustively!), but for the problem encountered it operated in Catch 22 mode - you had to do two things but neither order was permitted. I did find an answer eventually, but am not sure what it was I did that solved it! Thanks, anyway.

  • BIAPPS how can we manually set both ETL start date and end date?

    Dears experts,
    how can we manually set both ETL start date and end date while conducting incremental load IN DAC?
    Please advise me.
    thanks,
    Joe.

    You can set those dates in the DAC system parameters tab. You should see lots of $$xxxxxx parameters.
    If I may, I'd suggest you use the OBI Applications forum for questions on DAC.
    Antonio
    BExpert, Brazil

Maybe you are looking for