[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[xmlblaster] Java and C#



Dear sir,

I need to make a small communication using XMLblaster between two objects : Java and C#.

Mr.Zied made a file (Attached) for testing latency in Java and I need to make the same but in C# to make that small communication.

Could any body help please?

Thanks

Mohannad
import org.xmlBlaster.util.Global;
import org.xmlBlaster.util.SessionName;
import org.xmlBlaster.util.XmlBlasterException;
import org.xmlBlaster.client.qos.ConnectQos;
import org.xmlBlaster.client.qos.PublishQos;
import org.xmlBlaster.client.I_Callback;
import org.xmlBlaster.client.key.PublishKey;
import org.xmlBlaster.client.key.UpdateKey;
import org.xmlBlaster.client.qos.UpdateQos;
import org.xmlBlaster.client.I_XmlBlasterAccess;
import org.xmlBlaster.util.MsgUnit;
import java.util.Scanner;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import org.xmlBlaster.util.qos.address.Address;
import org.xmlBlaster.util.qos.address.CallbackAddress;


public class PingTest implements I_Callback
{
	private String oid="test";
	private Global glob;
	I_XmlBlasterAccess con;
	long fin = -1L;
	long debut = -1L;
	long latence = -1L; 
	static boolean t =true;
	static PrintWriter output = null;
	
/*	public static byte [] (byte y [], int n_byte){
		
		byte [] x = new byte [n_byte];
		for (int i = 0; i <n_byte; i++){
		
		}
	}*/

public PingTest(final Global glob) {
	t = false;
	try {
		this.glob =glob;		
		
		
		
		 // Parametre de connexion ( Obligatoire ) 
		  String[] args = { "-protocol", "XMLRPC",
	   		 "-dispatch/connection/plugin/xmlrpc/hostname", "172.16.128.43",
	   		 "-dispatch/connection/plugin/xmlrpc/port", "7766",
	   	//	"-dispatch/connection/plugin/xmlrpc/port","8080",
	   		"-dispatch/connection/plugin/xmlrpc/localHostname", "10.13.17.73",
	   	//	 "-dispatch/callback/plugin/xmlrpc/hostname","10.13.17.73",
	   	//	"-dispatch/connection/plugin/socket/localPort", "8888",  
	   		 "-dispatch/callback/plugin/socket/port","3412"
	         };
	       
	       
//	        String[] args = { "-DORBInitRef.NameService=file:///var/new/dbs/naming_hat/env.iro",
//	        "-dispatch/callback/plugin/socket/port","3412"
	        
	       //  };
	         	         
		  glob.init(args);
		  	  
//		Address address = new Address(glob);
//		address.setType("SOCKET");    // force SOCKET protocol
  //      address.setRawAddress("socket://noty:9988"); // Address to find the server
            
        
		con=glob.getXmlBlasterAccess();
         ConnectQos qos = new ConnectQos(glob);
         con.connect(qos, this);  // Login to xmlBlaster, register for updates
         System.out.println("Envoie d'un ping");
         debut=System.currentTimeMillis();
         System.out.println("debut : "+debut);
       
	 send("ping1234"); // send ping message
         
         //subscribe
         con.subscribe("<key oid='test'/>", "<qos/>");     
      }
      catch (Exception e) {
         System.err.println(e.getMessage());
      }
   }

void send(String cont)
{
    PublishKey pk = new PublishKey(glob, oid, "text/xml", "1.0");
    PublishQos pq = new PublishQos(glob);
    
	
    pq.setPersistent(false);
    
    
     byte [] content = cont.getBytes();
     byte [] x = new byte [content.length *2];
    for (int i = 0; i<(content.length *2);i++)
    {
    	if (i < content.length )
    	x[i] = content[i];
    	
    	else
    	x[i] = content[i/content.length];
    }
    
    System.out.println("The size................. is "+ x.length);
    MsgUnit msgUnit = new MsgUnit(pk, content, pq);    
    	
    try {
		
    	// 	publish
    	con.publish(msgUnit);

    } catch (XmlBlasterException e) {
		System.err.print(e);
	}	
} 
   //update : reception d'un message 
   public String update(String cbSessionId, UpdateKey updateKey, byte[] content,
                        UpdateQos updateQos)
   {
	   
	   String receive = new String(content);
	   
	   if (receive.equals("pong1234"))
	  // if (receive.has)
	    {
	   

	fin=System.currentTimeMillis();
        System.out.println("fin   : "+fin);
	   
	latence = (fin-debut)/2;
	System.out.println("latence : "+latence);
	output.println("latence "+latence );
       	   	
	    try {
		
	    	con.erase("<key oid='HelloWorld2'/>", null);
		
	    } catch (XmlBlasterException e) {
			e.printStackTrace();
		}

		con.disconnect(null);
	   t = true;
	   }
	   
	   return "";
   }

   
   public static void main(String args[]) {
      Global glob = new Global();

      if (glob.init(args) != 0) { // Get help with -help
         System.out.println(glob.usage());
         System.out.println("Example: java HelloWorld2 -session.name Jack");
         System.exit(1);
      }
      
      try{
      
      output = new PrintWriter(new File
                                  ("data.txt"));
	}
	 catch(FileNotFoundException e){
	 	System.out.println("Problem opening files.");
	 }
	 
	
	
      PingTest ping = new PingTest(glob);
	
    	// send 50 messages   
      	for (int i =0; i<50; i++)
      	{
     	while (!t){}
       new PingTest(glob);
      }
      
      output.close();    
}
}