7 public class net implements Runnable {
17 theQueue = new Queue();
20 private void println( String s ) {
21 System.out.println( ">" + s );
23 if( theSocket != null )
24 out.writeBytes( s + "\n" );
25 } catch( IOException ioe ) {
26 citadel.me.lostNetwork( "Connection dropped (write)" );
27 if( theSocket != null ) {
28 try { theSocket.close(); }
29 catch( Exception e ) {};
35 private String readLine( ) {
37 if( theSocket != null ) {
38 String s = in.readLine();
39 System.out.println( "<" + s );
42 } catch( IOException ioe ) {
43 citadel.me.lostNetwork( "Network error: read" );
44 if( theSocket != null ) {
45 try { theSocket.close(); }
46 catch( Exception e ) {};
53 public String getArch() {
55 Properties p = System.getProperties();
56 return p.get( "os.name" ) + "/" + p.get( "os.arch" );
57 } catch( SecurityException se ) {
62 public String getHostName() {
64 InetAddress me = InetAddress.getLocalHost();
65 return me.getHostName();
66 } catch( Exception e ) {
72 String server = citadel.me.server;
73 int port = citadel.me.port;
74 boolean proxy = false;
79 proxy = !server.equals( "127.0.0.1" );
82 theSocket = new Socket( "armstrong.cac.psu.edu", 13579 );
84 theSocket = new Socket( server, port );
87 in = new DataInputStream( theSocket.getInputStream() );
88 out = new DataOutputStream( theSocket.getOutputStream() );
89 } catch( IOException ioe ) {
90 citadel.me.lostNetwork( "Couldn't connect to server." );
99 citReply rep = getReply();
101 citadel.me.lostNetwork( "Couldn't connect: " + rep.line );
105 getReply( "IDEN 0|7|" + citadel.VERSION + "|" + citadel.NAME + " " +
106 citadel.VERSION + " (" + getArch() + ")|" + getHostName() );
108 Thread t = new Thread() {
110 while( !citadel.me.theNet.done ) {
112 Thread.sleep( 30000 );
113 } catch( Exception e ) {}
115 System.out.println( "Idle event" );
116 if( citadel.me.wo == null ) {
117 if( theQueue.empty() )
118 citadel.me.networkEvent( "NOOP" );
120 System.out.println( "...events pending" );
123 citadel.me.wo.refresh();
130 while( ((m = (MsgCmd)theQueue.get()) != null) && !done ) {
131 citReply r = getReply( m.cmd, m.data );
133 SwingUtilities.invokeLater( m );
137 if( theSocket != null )
139 } catch( IOException ioe ) {
142 citadel.me.lostNetwork( "Connection closed." );
146 } catch( Exception e ) {}
151 theQueue.append( null );
154 public void append( MsgCmd m ) {
155 theQueue.append( m );
158 public citReply getReply() {
159 return getReply( (String)null, (String)null );
162 public citReply getReply( String cmd ) {
163 return getReply( cmd, (String)null );
166 public citReply getReply( String cmd, String data ) {
167 if( cmd != null ) println( cmd );
169 citReply r = new citReply( readLine() );
170 if( r.listingFollows() ) {
171 while( r.addData( readLine() ) ) ;
174 if( r.sendListing() ) {
180 if( r.expressMessage() )
181 citadel.me.expressMsg();