Java Help!!!!!!!

Posted on 2004-11-15
Last Modified: 2010-03-31
This is a program i have written and it gives a Error when i run the code.
the command IDENTIFY is used to identify my progrm with the server following certain protocol rules.
the rules in detail could also be described

communicating with the server RULE:
Length - 2 bytes - {0,sum of all the datas in bytes}.
Command Code - 2 bytes {0,20}.
Data  - n bytes
protocol version number - (2 bytes) - {2,0}.
protocol version name - (String)
      length  - 2 bytes {0,6}.
      String .getBytes().

CheckSum - 2 bytes - {(byte)sum/256 ,(byte) sum%256}

//The IDENTIFY Command

long initTime = System.currentTimeMillis();

String protocol_Name = "Remote";
//byte[] identify = {0,10,0,20,2,0,0,0, 2,30};

byte[] identify = {0,16,0,20,2,0};
String PR_SName = "PRS2.0";

byte[] strarray = {0,(byte)PR_SName.length()};

//get the bytes for the string to be appended

byte[] prs = PR_SName.getBytes("UTF-8") ;

byte[] tmp1 = new byte[ strarray.length + prs.length ] ;

System.arraycopy( strarray, 0, tmp1, 0, strarray.length ) ;

System.arraycopy( prs, 0, tmp1, strarray.length, prs.length ) ;

strarray = tmp1 ;
//create a temp array the length we will need for the two arrays joined

byte[] tmp = new byte[ identify.length + strarray.length ] ;

//copy the original array into the start of our temp array

System.arraycopy( identify, 0, tmp, 0, identify.length ) ;

//copy the appended array into the end of our temp array
System.arraycopy( prs, 0, tmp, identify.length, strarray.length ) ;

//set the identify array to point to our newly created temp array
identify = tmp ;
int sum = 0;
for(int i = 0; i< identify.length; i++)
      sum += identify[i];
System.out.println("Sum of all the bytes =" + sum);
identify[identify.length - 2] = (byte)(sum / 256);

identify[identify.length - 1] = (byte)(sum % 256);
len = identify.length;
dos = new DataOutputStream(outstream);

length = instream.available();

System.out.println("Available bytes in IDENTIFY command =" + length);
dis = new DataInputStream(instream);
//BufferedReader br = new BufferedReader(new InputStreamReader(dis));
//BufferedInputStream bufferinput1 = new BufferedInputStream(instream);
for (int i=1; i<=length; i++)
               byte response = (byte);            
long timeTaken = System.currentTimeMillis()-initTime;
System.out.println("\n" + timeTaken + "Milli Seconds taken");
catch(InterruptedException e)
      System.err.println("Error =" + e);
Question by:ashok3sep
    LVL 37

    Expert Comment

    >> This is a program i have written and it gives a Error when i run the code.
    Maybe you can tell us what error exactly? (Stack trace)
    LVL 3

    Expert Comment

    Question is what is the error that it gives you?
    LVL 5

    Author Comment

    IO Exception Error
    LVL 35

    Expert Comment

    Post the full stack trace and also the line it occurs.
    LVL 37

    Accepted Solution

    The more info you give us the better we can help you.
    >>IO Exception Error
    At what line in your code?
    Like girionis said, please provide the full stack

    Other question: what is the variable "instream"?
    The definition isn't available in the code you posted.
    LVL 5

    Author Comment

    Anyway guys i solved it myself

    thanks for your help

    With regards,

    LVL 37

    Expert Comment


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Suggested Solutions

    For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
    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…
    Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
    This video teaches viewers about errors in exception handling.

    737 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

    22 Experts available now in Live!

    Get 1:1 Help Now