Showing posts with label Georgia Tech. Show all posts
Showing posts with label Georgia Tech. Show all posts

Friday, July 13, 2012

Java Socket Chat Application v0.1

This is a project for a couple of my CS1332 students. I have been working with them explaining how sockets and networking works specifically related to Java sockets. This is a quick proof of concept application that I threw together just to make sure that I was leading them in the right direction.

Right now it is an infinite loop that checks to see if the user has submitted text to the console or if the socket has received a string. All text is logged to an output file on each machine with the correct prefix to each message (">>" for incoming and "<<" for outgoing).



Code can be found below.

Server.java

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

public class Server {

    public static void main(String[] args) {
        try {
            ServerSocket sSocket = new ServerSocket(3000);
            Socket socket = sSocket.accept();
            System.out.println(\"Client accepted\");
            Chatter c = new Chatter(socket, \"Server.log\");
            c.run();
        } catch (IOException e) {
            // ignore
        }
    }
}

Client.java

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

public class Server {

    public static void main(String[] args) {
        try {
            ServerSocket sSocket = new ServerSocket(3000);
            Socket socket = sSocket.accept();
            System.out.println(\\\"Client accepted\\\");
            Chatter c = new Chatter(socket, \\\"Server.log\\\");
            c.run();
        } catch (IOException e) {
            // ignore
        }
    }
}

Chatter.java

import java.io.BufferedInputStream;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.Socket;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;

public class Chatter {
    private Socket socket;
    private BufferedInputStream bis;
    private ObjectInputStream ois;
    private ObjectOutputStream oos;
    private BufferedInputStream console_bis;
    private Scanner scanner;
    private BufferedWriter bfw;

    public Chatter(Socket socket, String logName) {
        try {
            this.socket = socket;
            this.bis = new BufferedInputStream(socket.getInputStream());
            this.oos = new ObjectOutputStream(socket.getOutputStream());
            this.console_bis = new BufferedInputStream(System.in);
            this.scanner = new Scanner(console_bis);
            this.bfw = new BufferedWriter(new FileWriter(new File(logName), true));
            this.bfw.append(\"\\n\\n\"
                    + new SimpleDateFormat(\"yyyy/MM/dd HH:mm:ss\")
                            .format(new Date()) + \"\\n===================\\n\");
            this.bfw.flush();
            
            this.ois = new ObjectInputStream(bis);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public void run() {
        String temp = \"\";
        while (temp == null || !temp.equals(\"quit\")) {
            temp = readSocketMessage();
            if (temp != null) {
                if (temp.equals(\"quit\")) {
                    System.out.println(\"[[ Other User Logged Off ]]\");
                    close();
                    System.exit(0);
                }
                logMessage(temp, true);
            }
            temp = readConsoleMessage();
            if (temp != null) {
                sendMessage(temp);
                logMessage(temp, false);
            }
        }
        this.close();
    }
    
    private void close() {
        try {
            socket.close();
        } catch (IOException e) {
            // ignore
        }
        try {
            bfw.close();
        } catch (IOException e) {
            // ignore
        }
    }

    private String readSocketMessage() {
        try {
            if (bis.available() > 0) {
                return (String) ois.readObject();
            }
        } catch (IOException e) {
            System.err
                    .println(\"Fatal Socket Exception: could not read message.\");
            System.exit(0);
        } catch (ClassNotFoundException e) {
            System.err.println(\"Socket Exception: peer sent bad input.\");
        }
        return null;
    }

    private String readConsoleMessage() {
        try {
            if (console_bis.available() > 0)
                return scanner.nextLine();
        } catch (IOException e) {
        }
        return null;
    }

    private void sendMessage(String message) {
        try {
            oos.reset();
            oos.writeObject(message);
            oos.flush();
        } catch (IOException e) {
            System.err
                    .println(\"Fatal Socket Exception: could not send message.\");
            System.exit(0);
        }
    }

    private void logMessage(String message, boolean display) {
        try {
            if (display) {
                System.out.println(\">> \" + message);
                bfw.append(\">> \");
            } else
                bfw.append(\"<< \");
            bfw.append(message).append(\"\\n\");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

Tuesday, June 12, 2012

AI Battle Challenge

Two Georgia Tech students are developing AI challenge platforms similar to the Google AI Challenges. This site will serve as online documentation of the development process as well as a resource for the AI challenge participants.

Look for games like:

  • Battleship
  • Minesweeper
  • Mancala
  • Pong

Check it out

Wednesday, May 9, 2012

Hytech Racing Project Notes and Status

Electrical Systems Current Status:


  • CAN Bus
    • Function in loopback mode
    • Error during bus communication (most likely due to transmission identification)
  • Pedal Node
    • Both accelerator pots tested and working
    • Both brake pots giving bad values
    • Serial communication confirmed
  • Engine Node
    • Function voltage divider and servo control code for maintaining lower nominal voltages.
    • Racing error when approaching 72V. I think this is because the voltage curve non-linear. Possible fix, larger resolution with custom gearbox.
    • IMPORTANT: need to remove common bus between 12V and 72V line
  • Motor Node
    • Further testing needed for successful RS232 communication with Kelly Controllers
  • Battery Node
    • Need battery protocol
  • Display/Safety Node
    • Successful serial communication
    • Successful LCD output
    • Low power schematic and functional circuit defined
**NOTE: Serial communication is not the same as CAN Bus communication


Electrical Systems Add-ons: 


  • Display/Safety Node
    • Netbook or old Android Phone: 
    • Large full color GUI with live monitoring
    • Computationally powerful and WIFI enabled.
    • Would allow real time network communication over WAN
    • GPS enabled
  • Client/Server Application
    • Allow real time monitoring/tweaking
    • Real time analysis and graphing


Notes: