Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ajout spécification #33

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions specs/rya-sge/PROTOCOLE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@


1. What transport protocol do we use?

Il faut utiliser TCP car le client va établir une connexion avec le serveur

2. How does the client find the server (adresses and ports ) ?

-Si le serveur a une IP et une adresse fixe, on peut coder en dur dans le code du client

-Il fait un broadcast avec UDP pour savoir qui offre les services recherchés et le serveur

lui répond en lui donnant son adresse

Remarques : Je n'ai pas bien compris comment on pouvait connaitre l'adresse IP du serveur sans découverte dynamique et sans coder en dur son IP(afin de faire tourner les serveurs sur différents machines )

- Who speaks first?

C'est le client qui parle en 1er, il contacte le serveur. Le serveur lui est en attente d'un client.

- What is the sequence of messages exchanged by the client and the server? (flow)

Server ---> Client : "Opération disponible : "DIV, MUL, SUB, ADD"

On peut se passer de l'étape ci-dessus pour simplifier le protocole.

Client --> Serveur : OPERATION n1 n2"

Exemple : DIV 1 2 veut dire que le serveur doit faire : 1 / 2

Serveur --> Client : RESULT res où res est le résultat

Client --> Server : FIN ou une autre OPERATION

- What happens when a message is received from the other party? (semantics)

L'autre partie récupère le message et le traite

- What is the syntax of the messages? How we generate and parse them? (syntax)

Il s'agit de commande, sauf le premier message du serveur qui est une string, il faut récupérer les arguments en fonction de la séquence du message

- Who closes the connection and when?

-Le serveur quand le client lui dit "FIN"

-Le serveur si le délai d'attente est dépassée(par exemple 5 minutes) afin d'éviter que le serveur soit en attente de client. Le délai s'applique dès que le serveur a envoyé un message au client et qu'il attend sa réponse. Cela "empêche"des attaques DDOS, smurf autre qui auraient pour but de monopoliser les ressources du serveur.

-Le client une fois qu'il a envoyé FIN au serveur

107 changes: 107 additions & 0 deletions specs/rya-sge/StreamingTimeServer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
package ch.heigvd.res.examples;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
* A very simple example of TCP server. When the server starts, it binds a
* server socket on any of the available network interfaces and on port 2205. It
* then waits until one (only one!) client makes a connection request. When the
* client arrives, the server does not even check if the client sends data. It
* simply writes the current time, every second, during 15 seconds.
*
* To test the server, simply open a terminal, do a "telnet localhost 2205" and
* see what you get back. Use Wireshark to have a look at the transmitted TCP
* segments.
*
* @author Olivier Liechti
*/
public class StreamingTimeServer {

static final Logger LOG = Logger.getLogger(StreamingTimeServer.class.getName());

private final int TEST_DURATION = 5000;
private final int PAUSE_DURATION = 1000;
private final int NUMBER_OF_ITERATIONS = TEST_DURATION / PAUSE_DURATION;
private final int LISTEN_PORT = 2205;

/**
* This method does the entire processing.
*/
private void start() throws Exception {
LOG.info("Starting server...");

ServerSocket serverSocket = null;
Socket clientSocket = null;
BufferedReader reader = null;
PrintWriter writer = null;

LOG.log(Level.INFO, "Creating a server socket and binding it on any of the available network interfaces and on port {0}", new Object[]{Integer.toString(LISTEN_PORT)});
serverSocket = new ServerSocket(LISTEN_PORT);
logServerSocketAddress(serverSocket);

while (true) {
LOG.log(Level.INFO, "Waiting (blocking) for a connection request on {0} : {1}", new Object[]{serverSocket.getInetAddress(), Integer.toString(serverSocket.getLocalPort())});
clientSocket = serverSocket.accept();

LOG.log(Level.INFO, "A client has arrived. We now have a client socket with following attributes:");
logSocketAddress(clientSocket);

LOG.log(Level.INFO, "Getting a Reader and a Writer connected to the client socket...");
reader = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
writer = new PrintWriter(clientSocket.getOutputStream());

LOG.log(Level.INFO, "Starting my job... sending current time to the client for {0} ms", TEST_DURATION);
for (int i = 0; i < NUMBER_OF_ITERATIONS; i++) {
writer.println(String.format("{'time' : '%s'}", new Date()));
writer.flush();
LOG.log(Level.INFO, "Sent data to client, doing a pause...");
Thread.sleep(PAUSE_DURATION);
}
reader.close();
writer.close();
clientSocket.close();
}
}

/**
* A utility method to print server socket information
*
* @param serverSocket the socket that we want to log
*/
private void logServerSocketAddress(ServerSocket serverSocket) {
LOG.log(Level.INFO, " Local IP address: {0}", new Object[]{serverSocket.getLocalSocketAddress()});
LOG.log(Level.INFO, " Local port: {0}", new Object[]{Integer.toString(serverSocket.getLocalPort())});
LOG.log(Level.INFO, " is bound: {0}", new Object[]{serverSocket.isBound()});
}

/**
* A utility method to print socket information
*
* @param clientSocket the socket that we want to log
*/
private void logSocketAddress(Socket clientSocket) {
LOG.log(Level.INFO, " Local IP address: {0}", new Object[]{clientSocket.getLocalAddress()});
LOG.log(Level.INFO, " Local port: {0}", new Object[]{Integer.toString(clientSocket.getLocalPort())});
LOG.log(Level.INFO, " Remote Socket address: {0}", new Object[]{clientSocket.getRemoteSocketAddress()});
LOG.log(Level.INFO, " Remote port: {0}", new Object[]{Integer.toString(clientSocket.getPort())});
}

/**
* @param args the command line arguments
*/
public static void main(String[] args) throws Exception {
System.setProperty("java.util.logging.SimpleFormatter.format", "%5$s %n");

StreamingTimeServer server = new StreamingTimeServer();
server.start();
}

}
8 changes: 8 additions & 0 deletions specs/rya-sge/server/.idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions specs/rya-sge/server/.idea/.name

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions specs/rya-sge/server/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions specs/rya-sge/server/.idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

124 changes: 124 additions & 0 deletions specs/rya-sge/server/.idea/uiDesigner.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
11 changes: 11 additions & 0 deletions specs/rya-sge/server/server.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
Loading