Link to home
Start Free TrialLog in
Avatar of alexgaga
alexgaga

asked on

ASN.1 module description

tried to use ASN.1 for a client server communication, but i'm not sure that i understand it correctly . The Client have to send an integer to the server, the server read it and send back a number and a String, the Client read them and send back a String the server read it and send back a String. It's something like this.
Client ---> server 1 integer

Server --> Client 1 integer
Server --> Client 1 String

Client ---> server 1 String
Server --> Client 1 String

Open in new window


I wrote the following ASN.1 module, I succeeded to generate the classes with jac asn1 but I am not sure that the description of the module are correct because the two sequence are exactly the same. I m not sure if i have to put only the variable that i will send or recive or both.



 
   Demo-module DEFINITIONS ::=       -- Module-name DEFINITIONS ::= BEGIN

    BEGIN

    Client ::= SEQUENCE {

    clientInt INTEGER ,

    serverInt INTEGER ,

    serverString BIT STRING ,

    clientString BIT STRING , serverResponse BIT STRING

    }

    Server ::= SEQUENCE {

    clientInt     INTEGER ,                 

    serverInt INTEGER ,

    serverString BIT STRING ,

    clientString BIT STRING , serverResponse BIT STRING

    }

    END -- end of module, END required

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of mccarl
mccarl
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of alexgaga
alexgaga

ASKER

Thank you for the answer


Demo-module DEFINITIONS ::=       -- Module-name DEFINITIONS ::= BEGIN

BEGIN
 
ClientFirstRequest ::= SEQUENCE {                   

   clientInt     INTEGER 

   }        

ServerFirstResponse ::= SEQUENCE {                

   serverInt    INTEGER ,        

   serverString     BIT STRING   
 
 }   

ClientSecondRequest ::= SEQUENCE {                   

   clientString     IA5String 

   }     

ServerSecondResponse ::= SEQUENCE {                

   serverResponse     IA5String 
 }   

 

END                                      -- end of module, END required

Open in new window


I still have one question :) before i was using sockets in my programm. Now it will be just the same thing ? I just code the object with ASN.1 send it via Spckets and decode it in the other side ?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Ok thank you, but my code was like this

Random rand = new Random();
int  n = rand.nextInt(50) + 1;
DataOutputStream dos = new DataOutputStream(_socket.getOutputStream());
 dos.writeInt(n);

Open in new window


I tried to make it like this
 
	int  n = rand.nextInt(50) + 1;
        ClientFirstRequest h = new ClientFirstRequest();
        h.setValue(4);
        DataOutputStream dos = new DataOutputStream(_socket.getOutputStream());
         dos.writeInt(h);

Open in new window


I tried to use setValue because in the  generated class ClientFirstRequest it say that i have to use it

package sequenceOfExample;

/*
 * Created by JAC (Java Asn1 Compiler)
 */

import com.turkcelltech.jac.*;
import com.chaosinmotion.asn1.Tag;

public class ClientFirstRequest extends Sequence
{
	/**
	 * if you want to set/fill an element below, just call the setValue(..) method over its instance.
	 *
	 * To encode/decode your object, just call encode(..) decode(..) methods.
	 * See 'TestProject.java' in the project to examine encoding/decoding examples
	 */
	public ASN1Integer clientInt = new ASN1Integer("clientInt");
	/* end of element declarations */
	
	/**
	* asn.1 SEQUENCE constructor
	*/
	public
	ClientFirstRequest()
	{
		super();
		setUpElements();
	}

	/**
	* asn.1 SEQUENCE constructor with its name
	*/
	public
	ClientFirstRequest(String name)
	{
		super(name);
		setUpElements();
	}
	

	protected void
	setUpElements()
	{
		super.addElement(clientInt);
	/* end of element setup */
	}
}

Open in new window


And one other question please, in the server, I have to create another abject FirstClientRequest to recive the object on it ?
thanx a lot
You have accepted my other answers so I'm not sure if that means that you were able to work this out, but just case you haven't this is what I think...

You can't use a DataOutputStream as well as ASN.1 encodings. They do similar things but in very different ways and so are not related as such. You need to use the methods of the classes created by the ASN/1 compiler, JAC. (See the comments on lines 15,16 of what you posted above).

So, I think you would need to do something like this...
	int  n = rand.nextInt(50) + 1;
        ClientFirstRequest h = new ClientFirstRequest();
        h.setValue(4);
        BerOutputStream bos = new BerOutputStream(_socket.getOutputStream());
         h.encode(bos);

Open in new window

Note: you will then need to import that BerOutputStream at the top of your java file...  import com.chaosinmotion.asn1.BerOutputStream;



As for the server side, it should be fairly similar except you would be using a BerInputStream along with the "decode" method of the FirstClientRequest object.
Thank you for the answer. No I still not able but I think that it will be better if I ask the question in new subject because it have nothing to do with the module description :D I will trie it and tell you if it work
Thank you for the answer. No I still not able but I think that it will be better if I ask the question in new subject because it have nothing to do with the module description :D I will trie it and tell you if it work