Go4Expert

Go4Expert (http://www.go4expert.com/)
-   Java (http://www.go4expert.com/forums/java/)
-   -   Taking data from a socket and storing it in an array (http://www.go4expert.com/forums/taking-data-socket-storing-array-t21369/)

colossusdub 15Mar2010 22:41

Taking data from a socket and storing it in an array
 
Hi,

i have x, y and z co-ordinates being sent over a socket every second, i want to store these in an array and the then read the three coordinates seperatley. can someone please help!

Thanks!!

Code:

import java.io.*;
import java.net.*;
import java.util.Scanner;
import java.io.File;



public class Combo2 {
    public static void main(String[] args) throws IOException {

        Socket kkSocket = null;
        PrintWriter out = null;
        BufferedReader in = null;
    File yourFile = new File("outs.txt");
    yourFile.delete();


        try {

            kkSocket = new Socket("192.168.33.39", 12000);
            out = new PrintWriter(kkSocket.getOutputStream(), true);
            in = new BufferedReader(new InputStreamReader(kkSocket.getInputStream()));
        } catch (UnknownHostException e) {
            System.err.println("Don't know about host: Adam.");
            System.exit(1);
        } catch (IOException e) {
            System.err.println("Couldn't get I/O for the connection to: Adam.");
            System.exit(1);
        }

        BufferedReader stdIn = new BufferedReader(new InputStreamReader(System.in));
        String fromServer;
        String fromUser;

        while ((fromServer = in.readLine()) != null)
      {

       
           
            if (fromServer.equals("Bye."))
                break;

 try{
    // Create file
   
        BufferedWriter a = new BufferedWriter(a);
   

outs.write( fromServer);
outs.newLine();
    //Close the output stream
    outs.close();




   
}



All times are GMT +5.5. The time now is 12:56.