~vcs-imports/jmeeting/trunk

« back to all changes in this revision

Viewing changes to org/devioux/jmeeting/client/JServer.java

  • Committer: silverfang
  • Date: 2008-03-23 02:45:59 UTC
  • Revision ID: vcs-imports@canonical.com-20080323024559-7cbw2l67ukjgx3zr
Basic messaging component

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package org.devioux.jmeeting.client;
 
2
 
 
3
import java.net.*;
 
4
import java.io.*;
 
5
 
 
6
 
 
7
public class JServer {
 
8
        public void dataListener(int port) throws IOException {
 
9
                ServerSocket serverSocket = null;
 
10
                
 
11
        try {
 
12
            serverSocket = new ServerSocket(port);
 
13
        } catch (IOException e) {
 
14
            System.err.println("Could not listen on port: " + port);
 
15
            System.exit(1);
 
16
        }
 
17
 
 
18
        Socket clientSocket = null;
 
19
        try {
 
20
            clientSocket = serverSocket.accept();
 
21
        } catch (IOException e) {
 
22
            System.err.println("Accept failed.");
 
23
            System.exit(1);
 
24
        }
 
25
 
 
26
        PrintWriter out = new PrintWriter(clientSocket.getOutputStream(), true);
 
27
        BufferedReader in = new BufferedReader(
 
28
                                new InputStreamReader(clientSocket.getInputStream()));
 
29
        String inputLine, outputLine;
 
30
        JProtocol jp = new JProtocol();
 
31
 
 
32
        outputLine = jp.processInput(null);
 
33
        out.println(outputLine);
 
34
        
 
35
        while ((inputLine = in.readLine()) != null) {
 
36
            outputLine = jp.processInput(inputLine);
 
37
            out.println(outputLine);
 
38
            if (outputLine.equals("Bye."))
 
39
                break;
 
40
        }
 
41
        out.close();
 
42
        in.close();
 
43
        clientSocket.close();
 
44
        serverSocket.close();
 
45
        }
 
46
        
 
47
    public static void main(String[] args) throws IOException {
 
48
        new JServer().dataListener(1208);
 
49
    }
 
50
}
 
51