0

I tried this code to send and receive an Integer with ASN.1 generated classes

Client sending an Integer:

ClientFirstRequest h = new ClientFirstRequest();
h.clientInt.setValue(9);
BerOutputStream bos = new BerOutputStream(_socket.getOutputStream());
h.encode(bos);

Server receiving it:

ClientFirstRequest h = new ClientFirstRequest();
BerInputStream in = new BerInputStream(socket.getInputStream());
h.decode(in);
ASN1Integer ClientNumber= h.clientInt;
int clientNumbervalue = (int)ClientNumber.getValue();

It work perfectly, but in the second sequence I have to send two argument, an Int and a String

Server sending an Integer and a String

ServerFirstResponse response1 = new ServerFirstResponse();
response1.serverInt.setValue(clientNumbervalue);
response1.serverString.setValue(randomString);
BerOutputStream bos = new BerOutputStream(socket.getOutputStream());
h.encode(bos);

Client receiving them

ServerFirstResponse response1 = new ServerFirstResponse();
BerInputStream in = new BerInputStream(_socket.getInputStream());
response1.decode(in);

But I got an error

com.chaosinmotion.asn1.AsnFatalException:

In decoding process, one of the elements of your SEQUENCE (or an element of an inner sequnce/set) is not OPTIONAL and not initialized! (If exists)name of this element is : serverString at com.turkcelltech.jac.Sequence.check_OptionalAndInitialized_Status(Sequence.java:259) at com.turkcelltech.jac.Sequence.fillSequenceVariables(Sequence.java:246) at com.turkcelltech.jac.Sequence.decode(Sequence.java:105) at Client.main(Client.java:54)

Donald_W
  • 1,773
  • 21
  • 35

1 Answers1

0

Please contact the vendor of the ASN.1 Tool you are using. They should be better able to how to handle errors in use of their ASN.1 Tool. Each ASN.1 vendor writes code differently even though the end result should be the same encoded stream of bytes regardless of which tool you are using. Note that you have not indicated here which ASN.1 Tool you are using.

Paul Thorpe
  • 1,930
  • 17
  • 23