tests/libjava-mauve/src/gnu/testlet/java/net/ServerSocket/BasicSocketServer.java
branchjk_new_structure
changeset 1541 75c2e24dea9a
parent 1540 92ac284961c1
child 1542 be11db817bcf
equal deleted inserted replaced
1540:92ac284961c1 1541:75c2e24dea9a
     1 // Tags: not-a-test
       
     2 
       
     3 /*
       
     4    Copyright (C) 1999, 2007 Hewlett-Packard Company
       
     5 
       
     6    This file is part of Mauve.
       
     7 
       
     8    Mauve is free software; you can redistribute it and/or modify
       
     9    it under the terms of the GNU General Public License as published by
       
    10    the Free Software Foundation; either version 2, or (at your option)
       
    11    any later version.
       
    12 
       
    13    Mauve is distributed in the hope that it will be useful,
       
    14    but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
       
    16    GNU General Public License for more details.
       
    17 
       
    18    You should have received a copy of the GNU General Public License
       
    19    along with Mauve; see the file COPYING.  If not, write to
       
    20    the Free Software Foundation, 59 Temple Place - Suite 330,
       
    21    Boston, MA 02111-1307, USA.
       
    22 */
       
    23 
       
    24 package gnu.testlet.java.net.ServerSocket;
       
    25 import gnu.testlet.TestHarness;
       
    26 import java.net.*;
       
    27 import java.io.*;
       
    28 
       
    29 
       
    30 class BasicSocketServer extends Thread {
       
    31   ServerSocket srvsock = null;
       
    32   
       
    33   private TestHarness harness;
       
    34   
       
    35   public void init(TestHarness harness)
       
    36   {
       
    37     this.harness = harness;
       
    38     try {
       
    39       srvsock = new ServerSocket(12000);
       
    40       harness.check(true);
       
    41     }
       
    42     catch (Exception e) {
       
    43       System.out.println("Error : BasicSocketServer::init failed " + 
       
    44 			 "exception in new ServerSocket(...) " + e);
       
    45       harness.debug(e);
       
    46     }
       
    47   }
       
    48   
       
    49   public void run()
       
    50   {
       
    51     harness.check(srvsock != null,
       
    52 		  "Error : BasicSocketServer::run failed  - 1 " + 
       
    53 		  "server socket creation was not successful");
       
    54     if (srvsock == null) {
       
    55       return;
       
    56     }
       
    57     
       
    58     int i = 0;
       
    59     while (i++ < 2) {
       
    60       try {
       
    61 	Socket clnt = srvsock.accept();	
       
    62 	
       
    63 	OutputStream os = clnt.getOutputStream();
       
    64 	DataOutputStream dos = new DataOutputStream(os);
       
    65 	dos.writeBytes("hello buddy");
       
    66 	dos.close();
       
    67 	harness.check(true);
       
    68       }
       
    69       catch (Exception e) {
       
    70 	System.out.println("Error : BasicSocketServer::run failed - 2" + 
       
    71 			   "exception was thrown");
       
    72 	harness.debug(e);
       
    73       }
       
    74     }
       
    75     try {
       
    76       srvsock.close();
       
    77       harness.check(true);
       
    78     }
       
    79     catch (Exception e) {
       
    80       System.out.println("Error : BasicSocketServer::run failed - 3" + 
       
    81 			 "exception was thrown");
       
    82       harness.debug(e);
       
    83     }
       
    84   }
       
    85 }