[Javanetsim-cvs] javaNetSim/core/protocolsuite/tcp_ip Telnet_client.java, 1.8, 1.9 Telnet_server.ja
Status: Beta
Brought to you by:
darkkey
From: QweR <qw...@us...> - 2006-09-05 21:04:48
|
Update of /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv21634/core/protocolsuite/tcp_ip Modified Files: Telnet_client.java Telnet_server.java Log Message: Index: Telnet_client.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/Telnet_client.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** Telnet_client.java 5 Sep 2006 14:59:52 -0000 1.8 --- Telnet_client.java 5 Sep 2006 21:04:36 -0000 1.9 *************** *** 1,4 **** /* ! * Echo.java * * Created on 19 Nov 2005 Ç., 14:09 --- 1,4 ---- /* ! * Telnet_client.java * * Created on 19 Nov 2005 Ç., 14:09 *************** *** 7,27 **** package core.protocolsuite.tcp_ip; - import core.TransportLayerException; - import core.InvalidNetworkLayerDeviceException; - import core.CommunicationException; - import core.LowLinkException; - import core.LayerInfo; - import core.Packet; - import core.Simulation; - import guiUI.TelnetEmulator; import core.ApplicationLayerDevice; /** --- 7,20 ---- package core.protocolsuite.tcp_ip; import core.TransportLayerException; import core.InvalidNetworkLayerDeviceException; import core.CommunicationException; import core.LowLinkException; import core.LayerInfo; import core.Packet; import core.Simulation; import guiUI.TelnetEmulator; import core.ApplicationLayerDevice; + import core.Error; /** *************** *** 36,39 **** --- 29,33 ---- private TelnetEmulator terminal; private int counts; + private boolean already_closed = false; private boolean connected; *************** *** 63,68 **** */ public void Close() throws TransportLayerException ! { ! mParentStack.FreeTCPApplication(this); } --- 57,65 ---- */ public void Close() throws TransportLayerException ! { ! if(!already_closed){ ! mParentStack.FreeTCPApplication(this); ! already_closed = true; ! } } *************** *** 111,127 **** public void DisconnectEvent(){ ! try{ ! connected = false; ! Disconnect(); ! } ! catch(TransportLayerException e) { ! printInfo("Client: can not disconnected: transport problem"); ! } ! catch(LowLinkException e) { ! printInfo("Client: can not disconnected: low link problem"); ! } ! printInfo("\nClient: receive disconnect event\n"); terminal.recvData("\nServer closed connection.\n"); ! terminal.recvData("\nQUIT"); } --- 108,131 ---- public void DisconnectEvent(){ ! connected = false; ! printInfo("Client: receive disconnect event"); terminal.recvData("\nServer closed connection.\n"); ! terminal.recvData("\nQUIT"); ! // try{ ! // printInfo("Client: receive disconnect event"); ! // Disconnect(); ! // } ! // catch(TransportLayerException e) { ! // printInfo("Client: can not disconnected: transport problem"); ! // } ! // catch(LowLinkException e) { ! // printInfo("Client: can not disconnected: low link problem"); ! // } ! // try{ ! // mParentStack.CloseTCP(this); ! // } ! // catch(TransportLayerException e){ ! // printInfo("Client: can not close port"); ! // } } *************** *** 133,152 **** public void Disconnect() throws TransportLayerException, LowLinkException{ ! if(connected){ ! try { ! mParentStack.FinalizeTCP(this); //will close client connection ! }catch(Exception e){ ! ///*TODO*: here to catch ! } ! ! if(appType==0){ printInfo("Client: closing connection."); ! }else{ ! printInfo("Client: closing connection. Now listening on " + listenPort + "."); ! } ! mParentStack.CloseTCP(this); ! //mParentStack.freeTCPPort(this); ! } ! } --- 137,153 ---- public void Disconnect() throws TransportLayerException, LowLinkException{ ! if(connected){ ! try{ ! mParentStack.FinalizeTCP(this); //will close client connection ! } ! catch(CommunicationException e){ ! printInfo("Client: can not disconnected: communication problem"); ! } printInfo("Client: closing connection."); ! mParentStack.CloseTCP(this); ! //mParentStack.freeTCPPort(this); ! connected = false; ! } ! } *************** *** 177,199 **** public void RecvData(String Data) throws LowLinkException, TransportLayerException { //processing the protocol doings. ! if(appType == 0){ //client processing recieve // printing some ... ! printInfo("Recieving echo message '" + Data + "' from server."); ! /* ! LayerInfo protInfo = new LayerInfo(getClass().getName()); ! protInfo.setObjectName(mParentStack.getParentNodeName()); ! protInfo.setDataType("Echo Protocol Data"); ! protInfo.setLayer("Application "); ! protInfo.setDescription("Recieving echo message '" + Data + "' from server."); ! Simulation.addLayerInfo(protInfo);*/ if(Data.compareTo("\nQUIT")==0) { ! connected = false; ! Disconnect(); // terminal.recvData("Client: closing connection\n"); } terminal.recvData(Data); ! } } --- 178,194 ---- public void RecvData(String Data) throws LowLinkException, TransportLayerException { //processing the protocol doings. ! // if(appType == 0){ //client processing recieve // printing some ... ! printInfo("Client: Recieving message '" + Data + "' from server."); if(Data.compareTo("\nQUIT")==0) { ! System.out.println("\n\n\n-----------------------\nTelnet: RecvData: QUIT\n-------------------------------\n\n\n"); ! // connected = false; ! // Disconnect(); // terminal.recvData("Client: closing connection\n"); } terminal.recvData(Data); ! // } } *************** *** 203,207 **** /** ! * This method processes a echo sending by client * @param data to send * @param server host --- 198,202 ---- /** ! * This method processes a telnet sending by client * @param data to send * @param server host *************** *** 257,261 **** } ! private void printInfo(String s) { LayerInfo protInfo2 = new LayerInfo(getClass().getName()); protInfo2.setObjectName(mParentStack.getParentNodeName()); --- 252,256 ---- } ! public void printInfo(String s) { LayerInfo protInfo2 = new LayerInfo(getClass().getName()); protInfo2.setObjectName(mParentStack.getParentNodeName()); Index: Telnet_server.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/Telnet_server.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** Telnet_server.java 28 Feb 2006 16:55:35 -0000 1.9 --- Telnet_server.java 5 Sep 2006 21:04:36 -0000 1.10 *************** *** 1,4 **** /* ! * Echo.java * * Created on 19 Nov 2005, 14:09 --- 1,4 ---- /* ! * Telnet_server.java * * Created on 19 Nov 2005, 14:09 *************** *** 22,25 **** --- 22,26 ---- import core.Simulation; import java.util.regex.*; + import core.Error; /** *************** *** 42,45 **** --- 43,47 ---- private String login = "root"; private String temp = ""; + private boolean connected; /** Creates a new instance of Telnet Server */ *************** *** 48,51 **** --- 50,54 ---- mDevice = dev; counts = 0; + connected = false; } *************** *** 57,66 **** public void Listen() throws TransportLayerException{ //throw new TransportLayerException("Cannot bind port " + listenPort + "."); ! try{ ! if(appType != 0) mParentStack.ListenTCP(this, listenPort); ! } catch (TransportLayerException e) ! { ! ! } isenter = true; } --- 60,64 ---- public void Listen() throws TransportLayerException{ //throw new TransportLayerException("Cannot bind port " + listenPort + "."); ! mParentStack.ListenTCP(this, listenPort); isenter = true; } *************** *** 84,88 **** /** ! * This method should be called from UDP when client connects to server * @author key * @version v0.01 --- 82,86 ---- /** ! * This method should be called from TCP when client connects to server * @author key * @version v0.01 *************** *** 91,94 **** --- 89,93 ---- sdHost = Host; sdPort = port; + connected = true; } *************** *** 100,118 **** public void DisconnectEvent(){ printInfo("Server: client closed connection"); ! try{ ! Close(); ! printInfo("Server: closing connection"); ! try{ ! Listen(); ! printInfo("Server: listening on port " + listenPort); ! } ! catch(TransportLayerException e){ ! printInfo("Server: can not listen on port " + listenPort); ! } ! } ! catch(TransportLayerException e){ ! printInfo("Server: can not close connection"); ! } } --- 99,118 ---- public void DisconnectEvent(){ + connected = false; printInfo("Server: client closed connection"); ! // try{ ! // printInfo("Server: closing connection"); ! // Close(); ! // try{ ! // Listen(); ! // printInfo("Server: listening on port " + listenPort); ! // } ! // catch(TransportLayerException e){ ! // printInfo("Server: can not listen on port " + listenPort); ! // } ! // } ! // catch(TransportLayerException e){ ! // printInfo("Server: can not close connection"); ! // } } *************** *** 124,141 **** public void Disconnect() throws TransportLayerException, LowLinkException{ try { ! mParentStack.FinalizeTCP(this); //will close client connection ! }catch(Exception e){ ! ///*TODO*: here to catch } ! if(appType==0){ ! printInfo("Server: closing connection."); }else{ ! printInfo("Server: closing connection. Now listening on port" + listenPort + "."); } ! ! mParentStack.CloseTCP(this); ! //mParentStack.freeTCPPort(this); } --- 124,142 ---- public void Disconnect() throws TransportLayerException, LowLinkException{ + connected = false; try { ! mParentStack.FinalizeTCP(this); //will close client connection ! }catch(CommunicationException e){ ! printInfo("Server: can not finalize TCP connection"); } ! Close(); ! Listen(); if(appType==0){ ! printInfo("Server: closing connection."); }else{ ! printInfo("Server: closing connection. Now listening on port " + listenPort + "."); } ! // mParentStack.CloseTCP(this); ! // mParentStack.freeTCPPort(this); } *************** *** 169,173 **** //server processing recieve ! printInfo("Server: recieving echo message '" + Data + "' from client."); while(Data.length()>0) { --- 170,174 ---- //server processing recieve ! printInfo("Server: recieving message '" + Data + "' from client."); while(Data.length()>0) { *************** *** 211,215 **** } catch(Exception e) { ! //************* } } --- 212,216 ---- } catch(Exception e) { ! Error.Report(e); } } *************** *** 255,271 **** } } ! try { printInfo("Server: sending message '" + outData + "' to client."); ! SendData(outData); ! if(outData.compareTo("\nQUIT")==0) { ! Close(); ! Listen(); ! printInfo("Server: closing connection"); ! printInfo("Server: listening on port " + listenPort); ! isenter = true; } - } - catch(Exception e){ - ///*TODO*: here to catch } Data = Data.substring(1); --- 256,285 ---- } } ! if(outData.compareTo("\nQUIT")==0) { ! Disconnect(); ! // try{ ! // Close(); ! // } ! // catch(TransportLayerException e){ ! // printInfo("Server: can not close application port"); ! // } ! // printInfo("Server: closed connection"); ! // try{ ! // Listen(); ! // } ! // catch(TransportLayerException e){ ! // printInfo("Server: can not listen on application port"); ! // } ! // printInfo("Server: listening on port " + listenPort); ! isenter = true; ! } ! else{ printInfo("Server: sending message '" + outData + "' to client."); ! try{ ! SendData(outData); ! } ! catch(CommunicationException e){ ! printInfo("Server: can not send data packet: communication error"); } } Data = Data.substring(1); |