KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > axis2 > transport > mail > server > SMTPServer


1 package org.apache.axis2.transport.mail.server;
2
3 import org.apache.axis2.context.ConfigurationContext;
4
5 import java.io.IOException JavaDoc;
6 import java.net.ServerSocket JavaDoc;
7 import java.net.Socket JavaDoc;
8
9
10 /**
11  * @author Chamil Thanthrimudalige
12  * @author Chamikara Jayalath
13  */

14
15 public class SMTPServer extends Thread JavaDoc{
16     private Storage st;
17     private ConfigurationContext configurationContext;
18     private int port;
19     public SMTPServer(Storage st,ConfigurationContext configurationContext,int port){
20         this.st = st;
21         this.configurationContext =configurationContext;
22         this.port = port;
23     }
24     public void run(){
25         runServer();
26     }
27
28     public void runServer() {
29         ServerSocket JavaDoc ss = null;
30         try {
31             ss = new ServerSocket JavaDoc(port);
32             System.out.println("SMTP Server started on port " + port);
33         } catch (IOException JavaDoc ex) {
34             ex.printStackTrace();
35         }
36
37         while (true) {
38             try {
39                 //wait for a client
40
Socket JavaDoc socket = ss.accept();
41                
42                 SMTPWorker thread = new SMTPWorker(socket, st,configurationContext);
43                 thread.start();
44             
45             } catch (IOException JavaDoc ex) {
46                 ex.printStackTrace();
47             }
48         }
49     }
50     
51 }
Popular Tags