tanszek:oktatas:tcp_socket_connection
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| tanszek:oktatas:tcp_socket_connection [2023/02/26 15:45] – [1.) Hagyományos blokkolt TCP alapú socket szerver] knehez | tanszek:oktatas:tcp_socket_connection [2023/02/27 09:16] (current) – [Exercise 1.] knehez | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ====== | + | ====== |
| + | |||
| + | ==== 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: | ||
| Line 7: | Line 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? (' | -) Client lists the files and asks the user what action they want to take? Upload or download? (' | ||
| - | -) 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. | ||
| Line 26: | Line 28: | ||
| -) If you press " | -) If you press " | ||
| - | ====== Starting point of implementation ====== | + | ==== TCP style ==== |
| Line 173: | Line 176: | ||
| } | } | ||
| </ | </ | ||
| - | ==== 2.) Hagyományos | + | ==== Traditional |
| - | 2.a) Az alábbi Ágens küld egy üzenetet és a 8080-as porton várja a választ rá, ugyancsak | + | The following Agent sends a message and waits for a response on port 8080, also with UDP. In the Eclipse IDE, the text you type on the console can be sent by pressing |
| - | **Feladat**: | + | == Exercise |
| + | Modify the code so that you can transfer | ||
| <code java> | <code java> | ||
| Line 207: | Line 211: | ||
| String modifiedSentence = new String(receivePacket.getData()); | String modifiedSentence = new String(receivePacket.getData()); | ||
| - | System.out.println(" | + | System.out.println(" |
| clientSocket.close(); | clientSocket.close(); | ||
| } | } | ||
| Line 213: | Line 217: | ||
| </ | </ | ||
| - | 2.b) Az UDP szerver a 8080-as porton várja az ágensek üzeneteit és nagybetűre konvertálva visszaküldi a kliens | + | 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 |
| <code java> | <code java> | ||
| Line 232: | Line 236: | ||
| DatagramPacket receivePacket = new DatagramPacket(bytesReceived, | DatagramPacket receivePacket = new DatagramPacket(bytesReceived, | ||
| - | // 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 | + | String |
| - | System.out.println(" | + | System.out.println(" |
| InetAddress IPAddress = receivePacket.getAddress(); | InetAddress IPAddress = receivePacket.getAddress(); | ||
| int port = receivePacket.getPort(); | int port = receivePacket.getPort(); | ||
| - | String | + | String |
| - | bytesSent = nagybetűsSzöveg.getBytes(); | + | bytesSent = upperCaseText.getBytes(); |
| - | // visszaküldi | + | // send back |
| DatagramPacket sendPacket = new DatagramPacket(bytesSent, | DatagramPacket sendPacket = new DatagramPacket(bytesSent, | ||
| serverSocket.send(sendPacket); | serverSocket.send(sendPacket); | ||
tanszek/oktatas/tcp_socket_connection.1677426327.txt.gz · Last modified: 2023/02/26 15:45 by knehez
