Solved

ASN.1 module description

Posted on 2013-05-11
8
474 Views
Last Modified: 2013-05-19
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

0
Comment
Question by:alexgaga
  • 5
  • 3
8 Comments
 
LVL 35

Accepted Solution

by:
mccarl earned 500 total points
ID: 39158163
You need to think of this in terms of what data is interchanged at each communication point. From what you are saying, you have FOUR separate communications that happen, eg. "Client 1st Request", "Server 1st Response", "Client 2nd Request", "Server 2nd Response". Hence you should have FOUR separate objects in your ASN.1 definitions, rather than the two you have above. That should be enough of a hint to get you going, but if you still have questions let us know.

PS. You probably don't want to use BIT STRING, what your after is probably more likely an IA5String.
0
 

Author Comment

by:alexgaga
ID: 39158189
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 ?
0
 
LVL 35

Assisted Solution

by:mccarl
mccarl earned 500 total points
ID: 39158197
Looks alright, although you still have one more bit string left in there.

Yeah, a socket would be fine. And I assume you are talking stream sockets, ie. TCP rather than UDP, which is also fine because the ASN.1 encodings include "length" information, so you can stick in the encoded bytes and the receiving end can still decode the object out of the stream.

Are you making a new connection from the client to server between the 1st and 2nd requests that we detailed above? If not, if you are just using the one socket connection, the only thing you may need to consider, is how both ends handle their "state" correctly, ie. if something gets screwed up along the way and one end thinks that they are up to the 2nd request/response and the other end the 1st, they will be sending a different object to what is expected. You may just have to think how to handle that case properly!
0
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 

Author Comment

by:alexgaga
ID: 39158404
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
0
 
LVL 35

Expert Comment

by:mccarl
ID: 39160185
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.
0
 

Author Comment

by:alexgaga
ID: 39168284
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
0
 

Author Comment

by:alexgaga
ID: 39168286
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
0
 

Author Comment

by:alexgaga
ID: 39178338
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
javap bin 2 36
delete-remove 14 87
Why isn't object file created? 6 59
printf performancy 11 43
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question