Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.BufferedReader;
- import java.io.FileWriter;
- import java.io.IOException;
- import java.io.InputStream;
- import java.io.InputStreamReader;
- import java.net.ServerSocket;
- import java.net.Socket;
- import java.io.FileNotFoundException;
- import java.io.PrintWriter;
- import java.io.UnsupportedEncodingException;
- import java.util.Arrays;
- import java.util.Calendar;
- import java.io.BufferedWriter;
- import javax.swing.JOptionPane;
- import java.io.*;
- import java.net.*;
- public class Camera extends Thread {
- // public static boolean first = true;
- long TimeoutStart;
- int TIMEOUT = 6000;
- int PositionfromSocket = 5;
- long timeDiff;
- // int[] line=new int[26];
- long receivedTime;
- String indexOfReceived;
- String rec;
- // static number m = null;
- BufferedReader in;
- BufferedReader d;
- BufferedWriter bw;
- Socket clientSocket;
- ServerSocket serverSocket;
- int[] a = new int[26];
- int j = 0;
- public Camera() throws IOException {
- bw = new BufferedWriter(new FileWriter("output.txt", true));// open file
- // to write
- // to it
- try {
- serverSocket = new ServerSocket(64540);
- } catch (IOException e1) {
- e1.printStackTrace();
- }
- }
- public void run() {
- try {
- // clientSocket = serverSocket.accept();
- // d = new BufferedReader(
- // new InputStreamReader(clientSocket.getInputStream()));
- clientSocket = serverSocket.accept();
- in = (BufferedReader) new BufferedReader(new InputStreamReader(
- clientSocket.getInputStream()));
- } catch (IOException e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- }
- int prev = 999;
- long timeCounter = System.currentTimeMillis();
- while (true) {
- try {
- for (int i = 0; i < 25; i++) {
- int x = in.read() - '0';
- a[j] = x;
- System.out.print(a[j]);
- j++;
- }
- System.out.print("\n");
- System.out.println("out");
- j=0;
- for(int i=0; i<25; i++)
- System.out.print(a[i]);
- System.out.print("\n");
- //System.out.println(" ");
- // for(int i=0;i<26;i++)
- // {
- // //line[i]=in.read()-'0';
- // bw.write(d.read());// add this line to file
- //
- //
- // }
- // if(in.readLine()!=null) System.out.println("line is null");
- // line="11111111111111111111111111";
- // System.out.println(in.read()-'0');
- receivedTime = System.currentTimeMillis();// get time now in
- // miliseconds
- // PositionfromSocket = Integer.parseInt(line.substring(0, 1));
- // // get
- // the
- // position
- // of
- // the
- // player
- // indexOfReceived = line.substring(14);// get the index
- // rec = line.substring(0, 1);// add the position to new line
- // rec += receivedTime + "";// add the received time
- // rec += indexOfReceived;// add the index
- // for(int i=0;i<line.length;i++){
- // System.out.print(line[i]);
- // bw.write(line[i]);// add this line to file
- // }
- // for(int i=0;i<line.length;i++)
- // bw.write((char)line[i]);
- // bw.newLine();
- // bw.newLine();
- bw.close();
- // PositionfromSocket = in.read()-'0';
- // System.out.println("Message time: "+(System.currentTimeMillis()-timeCounter));
- timeCounter = System.currentTimeMillis();
- // System.out.println("Socket Position "+PositionfromSocket);
- // if(PositionfromSocket<1 || PositionfromSocket>9)
- // { PositionfromSocket = prev;
- // }
- // else if((PositionfromSocket==prev))
- // {
- // timeDiff = System.currentTimeMillis() - TimeoutStart;
- // ConstantHandler.TimeOutProgress= (int)
- // ((TIMEOUT-timeDiff)*100/TIMEOUT);
- // if (timeDiff >= TIMEOUT)//test the time out, if we reach
- // timeout,
- // {
- // // ADD Visual Effects?????
- // ConstantHandler.ready=true;
- // ConstantHandler.position=PositionfromSocket;
- // //ConstantHandler.TimeOutProgress=0;
- // prev=999;
- // //TimeoutStart=System.currentTimeMillis();
- // //
- // System.out.println("Received Position "+ConstantHandler.position);
- // //JOptionPane.showMessageDialog(null,
- // ConstantHandler.position);
- // }
- //
- // }
- // else
- // {
- // ConstantHandler.position=PositionfromSocket;
- // TimeoutStart=System.currentTimeMillis();
- // ConstantHandler.TimeOutProgress=100;
- // //ConstantHandler.ready=true;
- // prev=PositionfromSocket;
- // }
- } catch (IOException e) {
- System.err.println("Can not read from camera module.");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement