• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2007 The Android Open Source Project
2 
3 import java.net.ServerSocket;
4 import java.io.IOException;
5 
6 
7 /**
8  * Quick server socket test.
9  */
10 public class Main {
snooze(int sec)11     private static void snooze(int sec) {
12         try {
13             Thread.sleep(sec * 1000);
14         } catch (InterruptedException ie) {
15             ie.printStackTrace();
16         }
17     }
18 
main(String[] args)19     public static void main(String[] args) {
20         ServerSocket socket;
21 
22         try {
23             socket = new ServerSocket(7890);
24         } catch (IOException ioe) {
25             System.out.println("couldn't open socket " + ioe.getMessage());
26             return;
27         }
28 
29         System.out.println("opened!");
30         snooze(1);
31 
32         try {
33             socket.close();
34         } catch (IOException ioe) {
35             System.out.println("couldn't close socket " + ioe.getMessage());
36             return;
37         }
38 
39         System.out.println("closed!");
40         snooze(1);
41 
42         try {
43             socket = new ServerSocket(7890);
44         } catch (IOException ioe) {
45             System.out.println("couldn't reopen socket " + ioe.getMessage());
46             return;
47         }
48 
49         System.out.println("reopened!");
50         System.out.println("done");
51     }
52 }
53 
54