Taking data from a socket and storing it in an array

Discussion in 'Java' started by colossusdub, Mar 15, 2010.

  1. colossusdub

    colossusdub New Member

    Joined:
    Mar 15, 2010
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    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();
    
    
    
    
        
    }
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice