1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

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