Felhasználói eszközök

Eszközök a webhelyen


tanszek:oktatas:tcp_socket_connection

Különbségek

A kiválasztott változat és az aktuális verzió közötti különbségek a következők.

Összehasonlító nézet linkje

Előző változat mindkét oldalon Előző változat
Következő változat
Előző változat
tanszek:oktatas:tcp_socket_connection [2023/02/26 15:45]
knehez [1.) Hagyományos blokkolt TCP alapú socket szerver]
tanszek:oktatas:tcp_socket_connection [2023/02/27 09:16] (aktuális)
knehez [Exercise 1.]
Sor 1: Sor 1:
-====== ​Exercise ​======+====== ​Socket client and server exercises ​====== 
 + 
 +==== Exercise 1. ====
  
 Create a simplified FTP (file transport) client and server where the client can send or download text files from the server: Create a simplified FTP (file transport) client and server where the client can send or download text files from the server:
Sor 7: Sor 9:
   -) Server sends back the list of the downloadable files   -) Server sends back the list of the downloadable files
   -) Client lists the files and asks the user what action they want to take? Upload or download? ('​u'​ or '​d'​) ​   -) Client lists the files and asks the user what action they want to take? Upload or download? ('​u'​ or '​d'​) ​
-  -) In both cases the uses must give the full file name with extension+  -) In both cases users must give the full file name with extension
   -) The client sends the selected file to the server (upload) or downloads the selected file from the server to a specific directory.   -) The client sends the selected file to the server (upload) or downloads the selected file from the server to a specific directory.
  
Sor 26: Sor 28:
   -) If you press "​u",​ /files/ is sent to the server   -) If you press "​u",​ /files/ is sent to the server
  
-====== Starting point of implementation ======+==== TCP style ==== 
  
  
Sor 173: Sor 176:
     }     }
 </​code>​ </​code>​
-==== 2.) Hagyományos ​UDP alapú kommunikáció ​====+==== Traditional ​UDP style ====
  
-2.a) Az alábbi Ágens küld egy üzenetet és a 8080-as porton várja a választ ráugyancsak ​UDP-velAz eclipse fejlesztőkörnyezetben a consolon beírt szöveget ​ctrl+z ​leütésével lehet elküldeni.+The following Agent sends message and waits for response on port 8080, also with UDP. In the Eclipse IDE, the text you type on the console can be sent by pressing ​ctrl+z
  
-**Feladat**:​ módosítsuk a kódot, hogy át tudjon küldeni egy beégetett nevű, és létező, ​kbyte-nál nagyobb szöveges vagy kép állományt és ellenőrizzük ​sikeres küldést.+== Exercise ​2. ==  
 +Modify the code so that you can transfer ​burned-in name and existing text or image file larger than 2 kbytes and verify that it was successfully sent.
  
 <code java> <code java>
Sor 207: Sor 211:
  String modifiedSentence = new String(receivePacket.getData());​  String modifiedSentence = new String(receivePacket.getData());​
   
- System.out.println("​átalakítva:" + modifiedSentence);​+ System.out.println("​converted:" + modifiedSentence);​
  clientSocket.close();​  clientSocket.close();​
  }  }
Sor 213: Sor 217:
 </​code>​ </​code>​
  
-2.b) Az UDP szerver a 8080-as porton várja az ágensek üzeneteit és nagybetűre konvertálva visszaküldi a kliens ​UDP socketre.+2.b) The UDP server waits for the agents messages on port 8080 and converts them to uppercase letters and sends them back to the client ​UDP socket.
  
 <code java> <code java>
Sor 232: Sor 236:
   
  DatagramPacket receivePacket = new DatagramPacket(bytesReceived,​ bytesReceived.length);​  DatagramPacket receivePacket = new DatagramPacket(bytesReceived,​ bytesReceived.length);​
- // itt várakozik ameddig adat jön a 8080-as porton+ // here we are waiting for the packets
  serverSocket.receive(receivePacket);​  serverSocket.receive(receivePacket);​
   
- String ​szoveg ​= new String(receivePacket.getData());​+ String ​textMessage ​= new String(receivePacket.getData());​
   
- System.out.println("​kaptam: " + szoveg);+ System.out.println("​I got: " + textMessage);
   
  InetAddress IPAddress = receivePacket.getAddress();​  InetAddress IPAddress = receivePacket.getAddress();​
  int port = receivePacket.getPort();​  int port = receivePacket.getPort();​
   
- String ​nagybetűsSzöveg ​szoveg.toUpperCase();​ + String ​upperCaseText ​textMessage.toUpperCase();​ 
- bytesSent = nagybetűsSzöveg.getBytes();​+ bytesSent = upperCaseText.getBytes();​
   
- // visszaküldi+ // send back
  DatagramPacket sendPacket = new DatagramPacket(bytesSent,​ bytesSent.length,​ IPAddress, port);  DatagramPacket sendPacket = new DatagramPacket(bytesSent,​ bytesSent.length,​ IPAddress, port);
  serverSocket.send(sendPacket);​  serverSocket.send(sendPacket);​
tanszek/oktatas/tcp_socket_connection.1677426327.txt.gz · Utolsó módosítás: 2023/02/26 15:45 szerkesztette: knehez