Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * @(#)OutputServer.java
- *
- * OutputServer application
- *
- * @author
- * @version 1.00 2010/1/17
- */
- import java.net.*;
- import java.io.*;
- public class OutputServer implements Runnable{
- private ServerSocket s;
- private Socket c;
- public static void main(String[] args) {
- OutputServer mainClass = new OutputServer();
- }
- public OutputServer() {
- try {
- /* Open a server socket */
- s = new ServerSocket(5555);
- /* Create a bridge from server to client */
- c = null;
- try {
- c = s.accept();
- new Thread(new OutputServer()).start();
- } catch (IOException ee) {
- System.err.print("Connection could not establish correctly.");
- System.exit(-1);
- }
- } catch (IOException e) {
- System.err.print("Trouble opening socket on port 5555, port in use?");
- System.exit(-1);
- }
- }
- public void run(){
- try {
- PrintWriter out = new PrintWriter(
- c.getOutputStream(), true);
- BufferedReader in = new BufferedReader(
- new InputStreamReader(
- c.getInputStream()));
- String inLine, outLine;
- MainProtocol mainProtocol = new MainProtocol();
- outLine = mainProtocol.processInput(null);
- out.println(outLine);
- while ((inLine = in.readLine()) != null) {
- outLine = mainProtocol.processInput(inLine);
- out.println(outLine);
- if (outLine == "Exit.") {
- break;
- }
- }
- out.close();
- in.close();
- c.close();
- } catch (Exception e) {
- System.err.print(e.getStackTrace());
- }
- }
- }
Add Comment
Please, Sign In to add comment