
-----------------------------------
shwetakode
Sun Sep 11, 2011 1:18 pm

ArrayIndexOutOfBoundsException 1 error while running a socket programming code
-----------------------------------
Hi,
I have written a socket programming code which reads a line from the user and sends to server character by character in the below format DATA seq_no char
eg : DATA1A (seq no : 1 , char = 'A')
it works fine for 1st character but getting exception for 2nd character.


Getting error at line :  --- god3[i+5]= god1[i];  Please help.


package again1;
import java.io.*;
import java.net.*; 



/**
 *
 * @author shweta
 */
public class Again1  {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws Exception {
        // TODO code application logic here
        
        String hostName = null;
        int servPort = 12346;
        
        try
        {
         hostName = args[0];    
        }     
        catch(ArrayIndexOutOfBoundsException e) {
        System.out.println("Need argument: remoteHost1234");
        System.exit(-1);
                                                }
        
        
         
        BufferedReader buffer = new BufferedReader(new InputStreamReader(System.in));
        DatagramSocket clientSocket = new DatagramSocket(); 
        
        int i=0,j=0;
               
        String sentence = null;
        System.out.println("Enter the string");
    sentence = buffer.readLine();
    InetAddress IPAddress = InetAddress.getByName(hostName); 
    byte[] god3 = new byte[6];
    byte[] god1 = new byte[6];
    
    god3[0] = 'D';
    god3[1]=  'A';
    god3[2]=  'T';
    god3[3]=  'A';
    
    for(i=0;i