annotate src/fdl/test2/Server.java @ 53:629b6cfbd37f

metaprotocol ring
author axmo
date Mon, 19 Jan 2009 17:49:14 +0900
parents
children 82a292aa41ad
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
53
629b6cfbd37f metaprotocol ring
axmo
parents:
diff changeset
1 package fdl.test2;
629b6cfbd37f metaprotocol ring
axmo
parents:
diff changeset
2
629b6cfbd37f metaprotocol ring
axmo
parents:
diff changeset
3 import java.net.*;
629b6cfbd37f metaprotocol ring
axmo
parents:
diff changeset
4 import java.io.*;
629b6cfbd37f metaprotocol ring
axmo
parents:
diff changeset
5 import java.util.*;
629b6cfbd37f metaprotocol ring
axmo
parents:
diff changeset
6
629b6cfbd37f metaprotocol ring
axmo
parents:
diff changeset
7 public class Server extends Thread{
629b6cfbd37f metaprotocol ring
axmo
parents:
diff changeset
8 static int Port = 10007;
629b6cfbd37f metaprotocol ring
axmo
parents:
diff changeset
9
629b6cfbd37f metaprotocol ring
axmo
parents:
diff changeset
10 public void run(){
629b6cfbd37f metaprotocol ring
axmo
parents:
diff changeset
11 try {
629b6cfbd37f metaprotocol ring
axmo
parents:
diff changeset
12 ServerSocket server = new ServerSocket(Port);
629b6cfbd37f metaprotocol ring
axmo
parents:
diff changeset
13 Socket sock =null;
629b6cfbd37f metaprotocol ring
axmo
parents:
diff changeset
14 System.out.println("Server Start");
629b6cfbd37f metaprotocol ring
axmo
parents:
diff changeset
15 sock = server.accept();
629b6cfbd37f metaprotocol ring
axmo
parents:
diff changeset
16 System.out.println("Connect");
629b6cfbd37f metaprotocol ring
axmo
parents:
diff changeset
17 PrintWriter ps = new PrintWriter(sock.getOutputStream());
629b6cfbd37f metaprotocol ring
axmo
parents:
diff changeset
18 Date d = new Date();
629b6cfbd37f metaprotocol ring
axmo
parents:
diff changeset
19 ps.print(d + "\r\n");
629b6cfbd37f metaprotocol ring
axmo
parents:
diff changeset
20 ps.flush();
629b6cfbd37f metaprotocol ring
axmo
parents:
diff changeset
21 sock.close(); // クライアントからの接続を切断
629b6cfbd37f metaprotocol ring
axmo
parents:
diff changeset
22 System.out.println("Connection Closed");
629b6cfbd37f metaprotocol ring
axmo
parents:
diff changeset
23 } catch (IOException e) {
629b6cfbd37f metaprotocol ring
axmo
parents:
diff changeset
24 // TODO Auto-generated catch block
629b6cfbd37f metaprotocol ring
axmo
parents:
diff changeset
25 e.printStackTrace();
629b6cfbd37f metaprotocol ring
axmo
parents:
diff changeset
26 }
629b6cfbd37f metaprotocol ring
axmo
parents:
diff changeset
27 }
629b6cfbd37f metaprotocol ring
axmo
parents:
diff changeset
28
629b6cfbd37f metaprotocol ring
axmo
parents:
diff changeset
29 public static void main(String[] args) {
629b6cfbd37f metaprotocol ring
axmo
parents:
diff changeset
30 Server sv = new Server();
629b6cfbd37f metaprotocol ring
axmo
parents:
diff changeset
31 sv.start();
629b6cfbd37f metaprotocol ring
axmo
parents:
diff changeset
32 }
629b6cfbd37f metaprotocol ring
axmo
parents:
diff changeset
33 }