

Public Member Functions | |
| ListenSocket (SocketHandler h, Socket creator) | |
| Creates a new instance of ListenSocket. | |
| Socket | Create () |
| void | OnInitialOps () |
| int | Bind (int port) |
| void | OnRead () |
| void | OnDelete () |
Private Attributes | |
| Socket | m_creator |
Definition at line 40 of file ListenSocket.java.
|
||||||||||||
|
Creates a new instance of ListenSocket.
Definition at line 44 of file ListenSocket.java. References net.alhem.jsockets.ListenSocket.m_creator. Referenced by net.alhem.jsockets.ListenSocket.Create(). 00045 {
00046 super(h);
00047 m_creator = creator;
00048 } //
|
|
|
Definition at line 58 of file ListenSocket.java. References net.alhem.jsockets.Socket.attach(), net.alhem.jsockets.Socket.Handler(), and net.alhem.jsockets.SocketHandler.LogError(). 00059 {
00060 // Instead of creating a ServerSocket,
00061 // create a ServerSocketChannel
00062 try
00063 {
00064 ServerSocketChannel ssc = ServerSocketChannel.open();
00065
00066 // Set it to non-blocking, so we can use select
00067 ssc.configureBlocking( false );
00068
00069 // Get the Socket connected to this channel, and bind it
00070 // to the listening port
00071 ServerSocket ss = ssc.socket();
00072 InetSocketAddress isa = new InetSocketAddress( port );
00073 ss.bind( isa );
00074
00075 attach(ssc);
00076 return 0;
00077 } catch (java.io.IOException e)
00078 {
00079 Handler().LogError(this, "Bind", 0, e.toString(), SocketHandler.LOG_LEVEL_ERROR);
00080 }
00081 return -1;
00082 } // Bind
|
|
|
Implements net.alhem.jsockets.Socket. Definition at line 49 of file ListenSocket.java. References net.alhem.jsockets.Socket.Handler(), net.alhem.jsockets.ListenSocket.ListenSocket(), and net.alhem.jsockets.ListenSocket.m_creator. 00050 {
00051 return new ListenSocket(Handler(), m_creator); //
00052 } // Create
|
|
|
Reimplemented from net.alhem.jsockets.Socket. Definition at line 122 of file ListenSocket.java. References net.alhem.jsockets.Socket.GetChannel(), net.alhem.jsockets.Socket.Handler(), and net.alhem.jsockets.SocketHandler.LogError(). 00123 {
00124 ServerSocketChannel sc = (ServerSocketChannel)GetChannel();
00125 try
00126 {
00127 sc.close();
00128 }
00129 catch (IOException e)
00130 {
00131 Handler().LogError(this, "OnDelete", 0, e.toString(), SocketHandler.LOG_LEVEL_ERROR);
00132 }
00133 } // OnDelete
|
|
|
Implements net.alhem.jsockets.Socket. Definition at line 53 of file ListenSocket.java. References net.alhem.jsockets.Socket.GetKey(). 00054 {
00055 GetKey().interestOps(SelectionKey.OP_ACCEPT);
00056 } // OnInitialOps
|
|
|
Reimplemented from net.alhem.jsockets.Socket. Definition at line 84 of file ListenSocket.java. References net.alhem.jsockets.SocketHandler.Add(), net.alhem.jsockets.Socket.attach(), net.alhem.jsockets.Socket.Create(), net.alhem.jsockets.Socket.GetChannel(), net.alhem.jsockets.Socket.Handler(), net.alhem.jsockets.SocketHandler.LogError(), net.alhem.jsockets.ListenSocket.m_creator, net.alhem.jsockets.Socket.OnAccept(), and net.alhem.jsockets.Socket.toString(). 00085 {
00086 try
00087 {
00088 ServerSocketChannel ssc = (ServerSocketChannel)GetChannel();
00089 java.net.ServerSocket ss = (java.net.ServerSocket)ssc.socket();
00090 // It's an incoming connection.
00091 // Register this socket with the Selector
00092 // so we can listen for input on it
00093 try
00094 {
00095 java.net.Socket js = ss.accept();
00096 System.out.println( "Got connection from " + js);
00097
00098 // Make sure to make it non-blocking, so we can
00099 // use a selector on it.
00100 SocketChannel sc = js.getChannel();
00101 sc.configureBlocking( false );
00102
00103 // Register it with the selector, for reading
00104 // sc.register( selector, SelectionKey.OP_READ );
00105
00106 Socket s = m_creator.Create();
00107 System.out.println("New Socket object: " + s.toString() );
00108 s.attach(sc);
00109 Handler().Add(s);
00110 s.OnAccept();
00111 }
00112 catch (Exception e)
00113 {
00114 Handler().LogError(this, "OnRead", 0, e.toString(), SocketHandler.LOG_LEVEL_ERROR);
00115 }
00116 } catch (java.lang.NullPointerException e)
00117 {
00118 Handler().LogError(this, "OnRead", 0, e.toString(), SocketHandler.LOG_LEVEL_ERROR);
00119 }
00120 } // OnRead
|
|
|
Definition at line 136 of file ListenSocket.java. Referenced by net.alhem.jsockets.ListenSocket.Create(), net.alhem.jsockets.ListenSocket.ListenSocket(), and net.alhem.jsockets.ListenSocket.OnRead(). |
1.3.9.1