summaryrefslogtreecommitdiffstats
path: root/tests/048-server-socket/src/Main.java
blob: 55dbf9a225297b7c441f1f9c214d5798f9f365fd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// Copyright 2007 The Android Open Source Project

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


/**
 * Quick server socket test.
 */
public class Main {
    private static void snooze(int sec) {
        try {
            Thread.sleep(sec * 1000);
        } catch (InterruptedException ie) {
            ie.printStackTrace();
        }
    }

    public static void main(String[] args) {
        ServerSocket socket;

        try {
            socket = new ServerSocket(7890);
        } catch (IOException ioe) {
            System.out.println("couldn't open socket " + ioe.getMessage());
            return;
        }

        System.out.println("opened!");
        snooze(1);

        try {
            socket.close();
        } catch (IOException ioe) {
            System.out.println("couldn't close socket " + ioe.getMessage());
            return;
        }

        System.out.println("closed!");
        snooze(1);

        try {
            socket = new ServerSocket(7890);
        } catch (IOException ioe) {
            System.out.println("couldn't reopen socket " + ioe.getMessage());
            return;
        }

        System.out.println("reopened!");
        System.out.println("done");
    }
}