Solved

ASN.1 module description

Posted on 2013-05-11
8
471 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
 

Author Comment

by:alexgaga
Comment Utility
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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 35

Expert Comment

by:mccarl
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
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…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.

744 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now