15/11/2022

This commit is contained in:
Lucàs
2022-11-15 15:08:16 +01:00
parent 313ee067e7
commit 3e70054728
5 changed files with 183 additions and 12 deletions
+56 -7
View File
@@ -1,17 +1,37 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ChangeListManager">
<list default="true" id="79e91d13-7d5f-4b9a-954b-9bc7cde074fc" name="Changes" comment="" />
<list default="true" id="79e91d13-7d5f-4b9a-954b-9bc7cde074fc" name="Changes" comment="">
<change afterPath="$PROJECT_DIR$/src/reseau/ResolutionDeNom.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/serveur/Serveur.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/Main.java" beforeDir="false" />
</list>
<list id="84fd72d2-dba6-4275-83d3-958fab491b17" name="Changes by burgu" comment="">
<change afterPath="$PROJECT_DIR$/src/client/Client.java" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
<option name="LAST_RESOLUTION" value="IGNORE" />
</component>
<component name="FileTemplateManagerImpl">
<option name="RECENT_TEMPLATES">
<list>
<option value="Class" />
</list>
</option>
</component>
<component name="Git.Settings">
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
</component>
<component name="MarkdownSettingsMigration">
<option name="stateVersion" value="1" />
</component>
<component name="ProjectId" id="2HaFpkE2ysQQKHoI2cE0i8sXNLB" />
<component name="ProjectLevelVcsManager" settingsEditedManually="true" />
<component name="ProjectLevelVcsManager" settingsEditedManually="true">
<ConfirmationsSetting value="2" id="Add" />
</component>
<component name="ProjectViewState">
<option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" />
@@ -20,20 +40,45 @@
"keyToString": {
"RunOnceActivity.OpenProjectViewOnStart": "true",
"RunOnceActivity.ShowReadmeOnStart": "true",
"WebServerToolWindowFactoryState": "false"
"WebServerToolWindowFactoryState": "false",
"codeWithMe.voiceChat.enabledByDefault": "false"
}
}]]></component>
<component name="RunManager">
<configuration name="Main" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
<option name="MAIN_CLASS_NAME" value="Main" />
<component name="RunManager" selected="Application.Client">
<configuration name="Client" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
<option name="MAIN_CLASS_NAME" value="client.Client" />
<module name="projet-mini-chat" />
<extension name="coverage">
<pattern>
<option name="PATTERN" value="client.*" />
<option name="ENABLED" value="true" />
</pattern>
</extension>
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
<configuration name="Serveur" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
<option name="MAIN_CLASS_NAME" value="serveur.Serveur" />
<module name="projet-mini-chat" />
<extension name="coverage">
<pattern>
<option name="PATTERN" value="serveur.*" />
<option name="ENABLED" value="true" />
</pattern>
</extension>
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
<list>
<item itemvalue="Application.Client" />
<item itemvalue="Application.Serveur" />
</list>
<recent_temporary>
<list>
<item itemvalue="Application.Main" />
<item itemvalue="Application.Client" />
<item itemvalue="Application.Serveur" />
</list>
</recent_temporary>
</component>
@@ -45,9 +90,13 @@
<option name="number" value="Default" />
<option name="presentableId" value="Default" />
<updated>1668515473737</updated>
<workItem from="1668515476841" duration="5510000" />
</task>
<servers />
</component>
<component name="TypeScriptGeneratedFilesManager">
<option name="version" value="3" />
</component>
<component name="Vcs.Log.Tabs.Properties">
<option name="TAB_STATES">
<map>
-5
View File
@@ -1,5 +0,0 @@
public class Main {
public static void main(String[] args) {
System.out.println("Hello world!");
}
}
+42
View File
@@ -0,0 +1,42 @@
package client;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;
import java.rmi.UnknownHostException;
public class Client {
public static void main(String[] args) throws IOException {
Socket echoSocket = null;
PrintWriter out = null;
BufferedReader in = null;
try {
echoSocket = new Socket("localhost", 4444);
System.out.println("Connecté au serveur");
out = new PrintWriter(echoSocket.getOutputStream(), true);
in = new BufferedReader(new InputStreamReader(echoSocket.getInputStream()));
} catch (UnknownHostException e) {
System.out.println("Destination unknown");
System.exit(-1);
} catch (IOException e) {
System.out.println("now to investigate this IO issue");
System.exit(-1);
}
BufferedReader stdIn = new BufferedReader(new InputStreamReader(System.in));
String userInput;
while ((userInput = stdIn.readLine()) != null) {
out.println(userInput);
System.out.println("echo: " + userInput);
}
out.close();
in.close();
stdIn.close();
echoSocket.close();
}
}
+27
View File
@@ -0,0 +1,27 @@
package reseau;
import java.net.InetAddress;
import java.net.UnknownHostException;
public class ResolutionDeNom {
public static InetAddress getAddress(String host) {
InetAddress address;
try {
address = InetAddress.getByName(host);
return address;
} catch (UnknownHostException e) {
e.printStackTrace();
}
return null;
}
public static void main(String[] args) {
// String input = args[0];
String input = "www.google.com";
InetAddress address = getAddress(input);
if (address != null) {
System.out.printf("%s : %s\n", input, address.getHostAddress());
}
}
}
+58
View File
@@ -0,0 +1,58 @@
package serveur;
import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;
public class Serveur {
public static void main(String[] args) {
ServerSocket serverSocket = null;
try {
serverSocket = new ServerSocket(4444);
} catch (IOException e) {
System.out.println("Could not listen on port 4444");
System.exit(-1);
}
Socket clientSocket = null;
try {
clientSocket = serverSocket.accept();
} catch (IOException e) {
System.out.println("Accept failed on port 4444");
System.exit(-1);
}
System.out.println("Client connecté");
boolean quitte = false;
boolean reception = true;
DataOutputStream envoi = null;
BufferedReader recevoir = null;
try {
OutputStream outputStream = clientSocket.getOutputStream();
envoi = new DataOutputStream(outputStream);
recevoir = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
while (!quitte) {
if (reception) {
String message = null;
while (message == null){
message = recevoir.readLine();
}
while(message != null){
System.out.println(message);
message= recevoir.readLine();
}
}
reception = !reception;
}
} catch (IOException e) {
e.printStackTrace();
}
}
}