Sock4Log - About
Sock4Log is a simple java xml server.
Sock4Log is a small server application which are listening for client connections on the specified port number. It is created for retrieving xml log data from Flash Swf aplications which are using XmlSocketConnection, but you can use Sock4Log for other programming languages (i.e. PHP or Java).
Running Sock4Log
Sock4Log is java application which are operating system independent. To run Sock4Log you should have JRE 5 installed.
To start application you can run :
command :
java -jar "Sock4Log.jar"
or batch file :
run.bat (Windows) 
run.sh (Linux)

Sock4Log screenshot
Configuration
You can configure Sock4Log changing "sock4log.properties" file. Sock4Log have two main output mode, Console (Terminal) and Swing (Windows).
# xml_socket_port integer (1228,65000) on wich port should server listening

xml_socket_port = 2124		


# Output mode
# SwingPublisher - output on desktop text area
# ConsolePublisher - output on terminal 

publisher = SwingPublisher


# decide which column to show in main view. 
#(false - hide, true - show)

show_sys_timestamp = false
show_time = false
show_message = true
show_file_name = false
show_class_name = true
show_line = true
show_level = false	
XML Log Message Format
To communicate with Sock4Log you should open socket the specified port number and send XML log message.
Simple XML log message format looks like this:
<log>
	<message>my message</message>
	<class_name>org.webservicesware.MyClass</class_name>
	<file_name>MyClass.as</file_name>
	<line>179</line>
</log>
Using Sock4Log with Flash and MTASC
This sample presents how to use Sock4Log with Flash using compiler MTASC.
You can download sources from here .


First file (Tracer.as) presents how to initialize connection with Sock4Log and send some message to opened socket.

Second file Main.as presents how to initialize Tracer and use native trace() function to send log message. Note that you have to use command:
-trace org.webservicesware.sock4log.Tracer.log 
to compile program with MTASC.

Tracer.as
	
/**
 * @author Rafal Malinowski 
 */
class org.webservicesware.sock4log.Tracer {
	private static var socket:XMLSocket = null;
	private static var isConnected : Boolean = false; 
	private static var toSendLogs:Array = new Array();
	
	public static function log(msg:String,clazz:String,file:String,line:Number) {
		var s:String = "<log>
		<message><![CDATA["+msg+" ]]></message>
		<class_name>"+clazz+"</class_name>
		<file_name>"+file+"</file_name>
		<line>"+line+"</line>
		</log>";
		if (isConnected)
			socket.send(s);
		else {
			toSendLogs.push(s);
		}
	}
	
	private static function initXMLSocket () : XMLSocket {
		var socket:XMLSocket = new XMLSocket();	
		
		socket.onConnect = function (success:Boolean) {
			if (success) {
				Tracer.onConnect();
					//trace ("Connection succeeded!");
			} else {
				//trace ("Connection failed!");
			}
		};		
		
		if (!socket.connect("localhost", 2124)) {
		 		//trace ("Connection failed!");
		}
		
		return socket;	
	}
	
	static function init() {
		Tracer.socket = Tracer.initXMLSocket();
	}
	
	public static function onConnect() {
		if (!Tracer.isConnected) {
			Tracer.isConnected = true;	
			for (var i : Number = 0; i < toSendLogs.length; i++) {				
				socket.send(toSendLogs[i]);
			}	
		}
		
	}
	
}
						


Main.as
	
					
/**
 * @author Rafal Malinowski
 */
 import org.webservicesware.sock4log.Tracer;
class org.webservicesware.sock4log.Main {
	
	public static function main(mc:MovieClip) {
		Tracer.init();
		trace("Trace before socket connected");
	
		
		mc.onMouseDown = function () {		
			trace ("Mouse Down " + " x: "+mc._xmouse+" y: "+mc._ymouse+"");
		};		

		mc.onMouseMove = function () {
			if (true)
				trace (getTimer()+" x: "+mc._xmouse+" y: "+mc._ymouse+"");
		};
	}  
}

						
Using Sock4Log with PHP
This sample presents how to use Sock4Log with PHP.
You can download sources from here .


First file (Sock4Log.class.php) presents how to send some message to opened socket.

Second file Usage.php presents example usage.

Sock4Log.class.php
	
class Sock4Log { public static $ip = "localhost"; public static $port = 2124; public static function trace($msg,$clazz,$file,$line) { Sock4Log::send(Sock4Log::getXMLLog($msg,$clazz,$file,$line)); } private static function getXMLLog($msg,$clazz,$file,$line) { return "<log><message><!--[CDATA[".$msg." ]]--></message> <class_name>".$clazz."</class_name> <file_name>".$file."</file_name> <line>".$line."</line></log>"; } private static function send($xmlLog) { $fp = fsockopen ( Sock4Log::$ip , Sock4Log::$port , &$errno , &$errstr , 1 ); fwrite($fp, $xmlLog.chr(0)); } }


Usage.php
	
						
Sock4Log::trace("Hello from:",__CLASS__,__FILE__,__LINE__);
Text me!
If you have any trouble with running this example, or Sock4Log, text me! I will always hapy to help you.



Download
Current Releases
Current version is 0.6.4 [ download ]
Examples
AS2 - MTASC - example presents how to init connection with Sock4Log and trace log message using free MTASC compiler. [ download ]
About me
rmalinowski.pl - my home page [ visit ]

My other projects
ASIoC is a very simple implementation of Dependency Injection (DI) pattern also known as Inversion of Control (IoC) written in Action Script 2.0.
[ more ]

GWT 2 SWF intend to provide software bridge between GWT and FLASH/FLEX. It's made for communication between GWT and FLASH/FLEX   [ more ]

GWT Reflection is a small framework which give you ability to use reflection API on client (JavaScript) side of application made by Google Web Toolkit.    [ more ]



 
SourceForge.net Logo