Προς το περιεχόμενο

Boi8eia se network protocols!!


**zefiros**

Προτεινόμενες αναρτήσεις

Δημοσ.

Kalispera se olous!Exw ws ergasia na ftiaxw se java tin proswmoiwsi tou "Sliding Window Protocol". Vasika prepei na ftiaxw enan server, enan client kai ena packet pou 8a to stelnei o client ston server kai o server 8a leei ka8e fora an to paketo 8a exei paralif8ei alliws 8a stelnei pisw ston client minima oti to paketo de paredw8ike. Exw katalavei ti paizei&pws prepei na to kanw panw katw alla to 8ema einai oti de borw na to kanw..Epcaksa sto google vrika kapia xrisima sites alla mexri ekei giati kanena den edeine source code gia na me voi8isei ligaki..an exei kaneis kamia idea i kati 8a me voi8ouse afantasta!!

Δημοσ.

Sliding Window Protocol ? Ti einai ayto ? Prwth fora to akoyw ayto to protokollo...

Anyway...dokimase edw, isws na se boh8hsei : http://java.sun.com/docs/books/tutorial/networking/sockets/index.html

 

An kai den kserw to format toy paketoy poy prepei na stelnei o client ston server, oyte polles leptomereies gia thn ergasia soy, ayto poy nomizw oti prepei na kaneis, einai to ekshs :

 

Server :

O server dhmioyrgei ena kainoyrgio socket poy 8a akoyei se ena proka8orismeno port gia paradeigma to 31337: ServerSocket s=new ServerSocket(31337);

Afoy dhmioyrgh8ei swsta to socket, o server perimenei gia nees syndeseis :

client=s.accept();

Ayth h klhsh oysiastika soy epistrefei ena neo socket (to client), to opoio einai hdh syndedemeno me to socket toy ypologisth o opoios ekane thn aithsh syndeshs.

An ginoyn mexri edw ola swsta, anoigeis ena stream gia diabasma apo to socket, kai ena stream gia grapsimo sto socket , wste na mporeis na labeis kai na steileis mhnymata antistoixa :

 

BufferedReader in=new BufferedReader(new InputStreamReader(client.getInputStream()));

 

PrintWriter out=new PrintWriter(new BufferedOutputStream(client.getOutputStream()),false);

 

Kai meta, to mono poy exeis na kaneis einai na akoloy8hseis ta bhmata toy prwtokolloy. Dhladh, an to protokolo leei oti o client stelnei ena string, kai o server toy apantaei me to idio to string mexri o client na steilei "quit", kaneis :

while(true)

{

String inLine=in.readLine();

if(inLine.equals("quit"))

break;

out.println(inLine);

out.flush();

}

 

Client:

O client einai poly pio eykolos, apla dhmioyrgei ena socket gia na synde8ei me ton server... :

Socket s=new Socket(ipAddressOfServer,31337);

kai streams eisodoy kai eksodoy gia diabasma kai grapsimo sto socket antistoixa :

BufferedReader in=new BufferedReader(new InputStreamReader(s.getInputStream()));

 

PrintWriter out=new PrintWriter(s.getOutputStream(),true);

 

Ayth einai mia aplh ylopoihsh. An twra 8eleis o server soy na mporei na xeirizetai pollaploys client taytoxrona (dld polyepeksergasia), tote 8a prepei otan o server epistrepsei apo to accept to neo socket (poy einai dyndedemeno me to socket toy pelath-client), na dhmioyrgeis ena kainoyrio thread wste na xeiristei aythn thn syndesh, enw to main thread toy server 8a ksanagyrizei sto accept wste na mporei na dextei kai alles aithseis.

 

Elpizw na mhn se mperdepsa perissotero...Phgaine sthn parapanw selida kai elpizw na bgaleis kapoia akrh.

Kalh tyxh...

Δημοσ.

panw katw auto pou eipes einai, mono pou anti gia string stelnei ena packet(gia tin akriveia 12 stelnei), diladi prepei na dimiourgisoume mia klassi pouna periexei ton ari8mo tou paketou&to onoma tou&meta 8aprepei na dimiourgi8ei ena objet autounou kai na stalei.analoga twra an to paketo parado8ei me epitxia ston server o server 8a prepei na steilei thetiki apantisi kai na proxwrisei sto epomeno paketo, an den stalei me epituxia 8a prepei pali na steilei apantisi oti den paredo8ike&8a prepei na xanaprospa8isei na to steilei, panw katw 8elei auto http://www.cs.stir.ac.uk/~kjt/software/comms/jasper/SWP3.html alla oxi toso proxwrimeno,arkei 2 frames me duo textarea pou aplws 8a tuponwntai epanw an paredo8ike i oxi

Δημοσ.

loipon oso anafora to protokolo kai ti leitouria tou genika (milaw gia ethernet diktio):

i diadikasia gia na parei enas user ena msg einai h eksis

1) stelnei ena paketo legomeno open to opoio theorite 72byte gia na arxisei h diadikasia to opoio molis ftasei ston server o server stelnei ena acknowlegment(tha to leme ACK) oti to open stalthike.

2)o user stelnei to msg aitish to opoio exei ka afto to diko tou ACK gia to an pige

3) exoume to close dil to paketo pou klinei ti diadikasia apo thn meria tou client kai to ACK tou close.

dil mexri twra gia ton client exoume 6 paketa

epeita exoume tin diadikasia tou server

1) omois to open kai to ACK tou

2)stelnei to file pou zhtithike kai to ACK tou file

3)to close kai to ACk

twra pou kolaei to sliding window...olo to zoumi einai sto megethos tou msg request kai to megethos tou file. to Ethernet xrisimopoiodas to CSMA/CD epitrepei metafora dedomenwn se ena paketo mexri (max) 1526bytes (ta opoioa omws einai kathara 1460 dioti to paketo pernei kapoioa byte legomena overhead apo to ehernet 26 byte kai apo to CSMA/CD 40 ta opoioa xrhsimopoioude gia genikes plhrofories, ara sinolo 1526) ara loipon an esena to file sou (pou tha stilei o server) einai 10000byte tha prepei na xwriseti se 6 paketa twn 1460byte kai ena twn 1240byte(ola afta xwris ta overhead milame gia ta kathara byte tou arxiou sou) ola afta prepei na paroun ena ACK opws pire kai to file tou user(pou tis perisoteres fores theoroume oti enia 1000byte)!twra logika an to skefteis tha eprepena exeis 1 ACK gia kathe paketo...afto omos tha kathisterouse poly ton rithmo metadwshs dedomenwn sto diktio kathws tha afksane tis siggouseis anamesa sta paketa...ara to sliding window (to opoio exei mia metavlith h opoioa legete window size h opoioa ypothetoume twra oti einai 3(dil 3 paketa)) kovei ena ACK ana 3(oso einai to window size) paketa...dil gia 6 paketa exoume 4 ack stadar! twra tha mou peis to 7mo paketo tha parei ack?to pirama sto programma prosomiosh s dixnei oti otan yparxei 1apo ta 3 paketa den pernei ack enw otan einai 2 pernei 1 ACK.

afta!elpizw na kataaves tpt(giati den ta grafw kai poly kalla!!) an theleis perisoteres diefkriniseis min distaseis na rwtiseis!!!!!!

good luck!

Αρχειοθετημένο

Αυτό το θέμα έχει αρχειοθετηθεί και είναι κλειστό για περαιτέρω απαντήσεις.

  • Δημιουργία νέου...