A kiválasztott változat és az aktuális verzió közötti különbségek a következők.
| Előző változat mindkét oldalon Előző változat Következő változat | Előző változat | ||
|
tanszek:oktatas:integration_based_on_tcp_ip_sockets [2023/03/05 16:05] knehez |
tanszek:oktatas:integration_based_on_tcp_ip_sockets [2023/03/05 16:22] (aktuális) knehez |
||
|---|---|---|---|
| Sor 1: | Sor 1: | ||
| + | ===== Socket communication ===== | ||
| + | |||
| The client sends requests to the server over a TCP socket connection, and the server responds to these requests. Here are the basic steps involved in integrating software systems or components using TCP socket communication: | The client sends requests to the server over a TCP socket connection, and the server responds to these requests. Here are the basic steps involved in integrating software systems or components using TCP socket communication: | ||
| Sor 9: | Sor 11: | ||
| - **Test and iterate**: Test the system thoroughly and make any necessary changes or improvements to ensure that it is functioning correctly. | - **Test and iterate**: Test the system thoroughly and make any necessary changes or improvements to ensure that it is functioning correctly. | ||
| - | **Summary**: | + | **Features**: |
| - | * Socket ::= IP address + (TCP/UPD) port number | + | * Socket ::= IP address + (TCP/UPD) port number. A Socket is a combination of ip address and port number. |
| * TCP Sockets provides 'real-time' data transfer | * TCP Sockets provides 'real-time' data transfer | ||
| - | * binary data transfer but can be normal text or XML as well | + | * binary data transfer but can be normal text or JSON, XML as well |
| - | * no direct method sharing (can be done by hand) | + | * no direct method sharing (can be implemented by hand) |
| - | * TCP and UDP connections are possible. UDP is 3 times quicker but one-way communication | + | * TCP and UDP connections are possible. UDP is min 3 times quicker but one-way communication |
| * Persistent or On-Demand communication channel | * Persistent or On-Demand communication channel | ||
| * because of connection time-loss usually persistent channels are better, but periodically 'ping' messages should be sent. (in order to avoid connection closing). In case of any problems reconnection is possible | * because of connection time-loss usually persistent channels are better, but periodically 'ping' messages should be sent. (in order to avoid connection closing). In case of any problems reconnection is possible | ||
| * in case of UDP channels an extra TCP channel is available for synchronizing - in online games | * in case of UDP channels an extra TCP channel is available for synchronizing - in online games | ||
| - | * Results in the fastest possible transmission. | + | * Results in the fastest possible transmission: |
| - | * Where the number of transactions per second up to ~ 20 transactions, there should have been applied. (50ms / sec transfer) | + | * Where the number of transactions per second up to ~ 50 transactions, there should have been applied. (20ms / sec transfer) |
| + | |||
| + | |||
| + | [[Java example for Blocking and Non-Blocking Socket]] | ||
| + | |||
| + | ** Exercise 1. ** | ||
| + | |||
| + | Create a simplified FTP (file transport) client and **blocking** server where the client can send or download text files from the server: | ||
| + | |||
| + | == General use-cases == | ||
| + | -) Client connects to the server and sends a 'file listing' message | ||
| + | -) 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') | ||
| + | -) 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. | ||
| + | |||
| + | |||
| + | == Server viewpoint == | ||
| + | -) After connecting, it reads the files from the /store subdirectory and sends the file names to the client after receiving the listing message. | ||
| + | -) We are waiting for the client's 'u' or 'd' operation | ||
| + | -) We get a filename from the client and if the action is 'd' (download), we read the file content and return its contents | ||
| + | -) If the operation is 'u' (upload), we open a new file with the specified name and wait for the data to be written to the file. | ||
| + | |||
| + | == Client viewpoint == | ||
| + | |||
| + | -) The client connects and waits for the list of files coming back and writes it to the console | ||
| + | -) We ask for the "u" or "d" key | ||
| + | -) Then we'll ask for the file-name as well. | ||
| + | -) The client reads the files from the /files folder, or creates the downloaded file here | ||
| + | -) If you press "d", it creates /files/ and writes data from the server | ||
| + | -) If you press "u", /files/ is sent to the server | ||
| + | |||
| + | |||
| + | ** Exercise 2. ** | ||
| + | Modify the **non-blocking** code so that you can transfer a burned-in name and existing text or image file larger than 2 kbytes and verify that it was successfully sent. | ||
| + | |||