Sending Live Data to XGRAPH
(Driving XGRAPH Interactively through Sockets)


To drive XGRAPH interactively from another program via a socket:     (IE. "Live-Plots")

Start XGraph with the -soc xx option, where xx is the socket your program will send data to XGraph on. Then your program should connect to that socket and send data points to plot over that socket, just as you would write lines to a file. Each line sent to XGraph through the socket must be terminated by a new-line, just as lines in a file would be.

You can send data points as well as most other commands that XGraph normally accepts from files. You can write your client applications in any language, such as C, C++, Java, Python, etc., as long as you can open a socket and write lines of characters to it. (The communications is one-way, and by using TCP/IP there is no hand-shaking needed.)

We provide a working example programs in C-language and Java that you can use. Below are some key points to writing your own client applications to plot through XGraph, using C programs as an example:

  1. In the global-area of your program:
    	#include "soclib.c"
    	Socket_record *soc;
       
  2. In the initialization section of your program, open the socket with:
    	soc = Setup_Client_Socket( "", socnum );
    Where socnum is an integer socket number, such as 13330 .
    (Use socket port numbers from 1024 up to 65535.)
    The empty quotes defaults to the your local computer (localhost). Alternately you could specifiy localhost or the IP-address of a remote computer running XGraph.

  3. Everywhere that you want to write data to XGRAPH, where you would normally write to a graph-file with:
    . . . fprintf( plotfile, "%f %f\n", x, y );
    Replace with:
    	sprintf( message, "%f %f", x, y );
    	Send_Socket( soc, message );
    
    (Note that you can send most any XGRAPH command through the socket
     that you would normally write to a plot-file, such as:
    	color = 8
    	next
            annotation 3.0 5.6  Any text you want
     etc..
    )

  4. Make sure your program closes the socket after it is done writing everything to XGRAPH, by:
    	Close_Socket( soc );


Usage:

  1. Invoke XGRAPH, specify the X-and-Y ranges, and the socket number(s) to use. Run it in one window.
    For example:
    	xgraph -x_range 0 20  -y_range 1 10  -soc 13330
    	
  2. Invoke your user-application in another window to send data-points on the given socket. For example:
    	livetest.exe 13330
    	


Notes: