Tbta va dtkafedrasi tarmoqni dasturlash asoslari



Download 361,74 Kb.
bet6/6
Sana07.01.2022
Hajmi361,74 Kb.
#327363
1   2   3   4   5   6
Bog'liq
TDA MI - 2 Gaybullayev

NVTPriter sinf kodi

class NVTPrinter extends Thread {

NVTInputStream inStream;

public NVTPrinter(NVTInputStream in){

//super();

inStream=in;

}

public void run(){



boolean finished=false;

try{


do{

int i=inStream.read();

if(i==-1){

finished=true;

}

else{


System.out.print((char)i);

System.out.flush();

yield();

}

//System.out.println("\n");



}while(!finished);

System.out.println("The Connection is aborted....");

System.exit(1);

}catch(IOException e){

System.out.println("Network Virtual Terminal Error");

}}

NVTOutputStream klassi

class NVTOutputStream extends FilterOutputStream{

int IAC=255;

byte CR=13;

byte LF=10;

public NVTOutputStream(OutputStream output){

super(output);

}

public void write(int i) throws IOException{



super.write(i);

}

public void println(String s){



try{

byte [] bytes=s.getBytes();

for(int i=0;i

super.write(bytes[i]);

}

super.write(CR);



super.write(LF);

super.flush();

}catch(IOException e){

System.out.println(" Input output Error");

} } }

NVTInputStream klassi



class NVTInputStream extends FilterInputStream{

byte IAC=(byte)0xFF;

byte DO=(byte)0xFD;

byte WILL =(byte)0xFB;

byte CR=13;

byte LF=10;

int wont=252;

int dont=254;

int bufferSize=1024;

OutputStream out;

byte [] linebuf=new byte[bufferSize];

int numBytes=0;

public NVTInputStream(InputStream inStream,OutputStream outStream){

super(inStream);

out=outStream;

}

public int read () throws IOException{



boolean recIAC;

int i;


do{

recIAC=false;

i=in.read();

if(i==-1) {

return i;

}

else if(IAC==i){



recIAC=true;

int cmd=in.read();

if(cmd==-1){

return cmd;

}

else{


byte b2=(byte)cmd;

if(b2==IAC){

return 255;

}

if(b2==WILL){



int opt=in.read();

if(opt==-1){

return opt;

}

out.write(255);



out.write(dont);

out.write(opt);

out.flush();

}

if(b2==DO){



int opt=in.read();

if(opt==-1){

return opt;

}

out.write(255);



out.write(wont);

out.write(opt);

out.flush();

} } }


}while(recIAC); return i; }

public String readLine() throws IOException {

numBytes=0;

boolean finished=false;

do{

int i=read();



if(i==-1)

return null;

else{

byte b=(byte)i;



if(b==LF){

if(numBytes>0){

if(linebuf[numBytes-1]==13){

return new String(linebuf,0,numBytes-1);

} } }

linebuf[numBytes]=b;



++numBytes;

}

}while(!finished);



return null; } }

Port klassi

class port extends Thread{

Socket con;

OutputStream out;

NVTInputStream in;

NVTPrinter printer;

public port(String [] args){

System.out.println("length"+args.length);

if(args.length!=2){

System.out.println("Use: Java Telnet host port");

System.exit(2);

}


String destination=args[0];

int port =0;

port=Integer.parseInt(args[1]);

System.out.println("Connecting to "+destination +" on " +port);

try{

con=new Socket(destination,port);



}catch(UnknownHostException e){

System.out.println("Unknown Destination..Try again...");

System.exit(3);

}


catch(IOException e){

System.out.println("Error While Creating the Socket");

System.exit(3);

}


try{

out=con.getOutputStream();

in=new NVTInputStream(con.getInputStream(),out);

}catch(IOException e){

System.out.println("Input Output Error...");

System.exit(3);

}

System.out.println("Connection Established..");



}

public void ProcessInput(){

try{

String line;



boolean finished=false;

BufferedReader read=new BufferedReader(new InputStreamReader(System.in));

do{

line=read.readLine();



if(line==null){

finished=true;

}else{

try{


for(int i=0;iout.write(line.charAt(i));

out.write('\n');

}


}catch(IOException e){

System.out.println("Input Output Error...");

System.exit(3);

}


}

}while(!finished);

} catch(IOException e){

System.out.println("Input Output Error...");

System.exit(3);

}


}

public void shutdown(){

try{

con.close();



}catch(IOException e){

System.out.println("Error Closing the Socket");

System.exit(3);

}


}

public void run(){

printer =new NVTPrinter(in);

printer.start();

yield();

this.ProcessInput();

shutdown();

}


}

Telnet sinf namunasi

//This is a sample Telnet app coded using java

import java.net.*;

import java.rmi.UnknownHostException;

import java.io.*;

Public class Telnet {

public static void main(String [] str){

for(int i=0;i

System.out.println("<<>>"+str[i]);

}


port p=new port(str);

p.start();



}

}





Download 361,74 Kb.

Do'stlaringiz bilan baham:
1   2   3   4   5   6




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish