From: Bill S. <wst...@co...> - 2005-04-15 15:54:44
|
All, I'm new to Jython and have been asked to create a script to report some metrics to a Daemon (C code) process on my localhost. I can connect to the daemon and write my metric, but cannot read the response to verify that the metric was accepted. I wrote a class in Java using a BufferedReader and PrintWriter(autoflush on) and had no problem. Why won't Jython work with the same setup? Thanks, Bill S. here is my sample code....(Jython 2.1) from java.io import * from java.net import * from java.util import Date host = "localhost" # Host machine port = 1029 # webhappi port metricFormat='PREFIX:EPOCH:METRICNAME=METRICVALUE' # Connect to foreign machine and open streams s = Socket(host, port) bin = BufferedReader(InputStreamReader(s.getInputStream())) # set autoflush for PrineWriter out = PrintWriter(OutputStreamWriter(s.getOutputStream()), 1) print s.toString() print bin.toString() print out.toString() #format metric report string prefix='smi_wl' date = Date() epochTime = date.getTime()/1000 mString = "%s:%d:%s=%d\n" % (prefix, epochTime, 'jvmFree', epochTime) print mString # Send request out.print(mString) print "metric printed" # read response, should be "PASS" #response = bin.readLine() #print response # logout bye="BYE"; out.print(bye) print "BYE printed" # # close both streams and the socket # out.close() bin.close() s.close() |
From: Bill S. <wst...@co...> - 2005-04-15 16:59:00
|
Jeff, Thanks for that. It did the trick. Bill Jeff Emanuel wrote on 4/15/2005, 12:46 PM: > > I think you need to call out.println instead of out.print > for the PrintWriter to flush. > > "autoFlush - A boolean; if true, the println, printf, or format > methods will flush the output buffer" > > Bill Stephens wrote: > > All, > > > > I'm new to Jython and have been asked to create a script to report some > > metrics to a Daemon (C code) process on my localhost. I can connect to > > the daemon and write my metric, but cannot read the response to verify > > that the metric was accepted. > > > > I wrote a class in Java using a BufferedReader and > PrintWriter(autoflush > > on) and had no problem. Why won't Jython work with the same setup? > > > > Thanks, > > Bill S. > > > > here is my sample code....(Jython 2.1) > > > > > > from java.io import * > > from java.net import * > > from java.util import Date > > > > host = "localhost" # Host machine > > port = 1029 # webhappi port > > metricFormat='PREFIX:EPOCH:METRICNAME=METRICVALUE' > > > > # Connect to foreign machine and open streams > > s = Socket(host, port) > > bin = BufferedReader(InputStreamReader(s.getInputStream())) > > > > # set autoflush for PrineWriter > > out = PrintWriter(OutputStreamWriter(s.getOutputStream()), 1) > > > > print s.toString() > > print bin.toString() > > print out.toString() > > > > #format metric report string > > prefix='smi_wl' > > date = Date() > > epochTime = date.getTime()/1000 > > mString = "%s:%d:%s=%d\n" % (prefix, epochTime, 'jvmFree', epochTime) > > print mString > > > > # Send request > > out.print(mString) > > print "metric printed" > > > > # read response, should be "PASS" > > #response = bin.readLine() > > #print response > > > > # logout > > bye="BYE"; > > out.print(bye) > > print "BYE printed" > > > > # > > # close both streams and the socket > > # > > out.close() > > bin.close() > > s.close() > > > > > > > > > > > > > > ------------------------------------------------------- > > SF email is sponsored by - The IT Product Guide > > Read honest & candid reviews on hundreds of IT Products from real > users. > > Discover which products truly live up to the hype. Start reading now. > > http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click > > _______________________________________________ > > Jython-dev mailing list > > Jyt...@li... > > https://lists.sourceforge.net/lists/listinfo/jython-dev |