Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

ASN.1 module description

Posted on 2013-05-11
8
Medium Priority
?
488 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
8 Comments
 
LVL 36

Accepted Solution

by:
mccarl earned 2000 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 36

Assisted Solution

by:mccarl
mccarl earned 2000 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
Build and deliver software with DevOps

A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.

 

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 36

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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.
Suggested Courses

715 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