From 2da6a97900af30a4843974dbb0c414570389acf3 Mon Sep 17 00:00:00 2001 From: JL-HEIG Date: Wed, 31 Mar 2021 14:17:01 +0200 Subject: [PATCH 1/3] PROTOCOL written --- specs/jlheig/PROTOCOL.md | 55 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 specs/jlheig/PROTOCOL.md diff --git a/specs/jlheig/PROTOCOL.md b/specs/jlheig/PROTOCOL.md new file mode 100644 index 0000000..e38e9d4 --- /dev/null +++ b/specs/jlheig/PROTOCOL.md @@ -0,0 +1,55 @@ +# RES - Exercise-protocol-Design 2021 + +Authors : Jean-Luc Blanc + +Date : 31.03.2021 + +------ + +### What transport protocol do we use? + +TCP/IP, most used and popular one. It is also the default one with Java sockets. + +### How does the client find the server? + +When you start a server, it shows the port its listening to. So the client simply has to connect to that port through the right ip adress. + +### Who speaks first? + +There are no right or wrongs, but usually clients speak first, this therefor allows the server to decide to accept or not the connection of the client + +### What is the sequence of messages exchanged by the client and the server? + +1. Server listens to a port +2. Client try connecting to the server +3. Server accepts +4. Server is waiting for a calculation +5. Client sends one +6. Server receives it and compute it +7. Server sends an answer to the client +8. Client receives it +9. Client can either ask a new calculation or simply disconnect + +### What happens when a message is received from the other party? + +Depends on what message was send : +* if the message sent is an invalid command, we send an error message +* if the message is a valid command then we simply send the answer to the calculation + +### What is the syntax of the messages? How do we generate and parse them? + +That's an arbitrary choice, I would go for that : +* add n1 n2 +* sub n1 n2 +* mult n1 n2 +* div n1 n2 + +Most basic operations can be decomposed in this form : +* operation +* number on the left +* number on the right + +### Who closes the connection and when? + +The client decides when to close the connection + From 2a9815bc1127cf5f381ff5a725dda76d5479f774 Mon Sep 17 00:00:00 2001 From: JL-HEIG Date: Wed, 31 Mar 2021 16:46:18 +0200 Subject: [PATCH 2/3] Server and Client implementation, still debugging --- specs/jlheig/Code/.idea/workspace.xml | 46 ++++++++ specs/jlheig/Code/Client/.idea/.gitignore | 3 + specs/jlheig/Code/Client/.idea/misc.xml | 6 ++ specs/jlheig/Code/Client/.idea/modules.xml | 8 ++ specs/jlheig/Code/Client/.idea/vcs.xml | 6 ++ specs/jlheig/Code/Client/Client.iml | 11 ++ .../Client/out/production/Client/Client.class | Bin 0 -> 3148 bytes specs/jlheig/Code/Client/src/Client.java | 89 +++++++++++++++ specs/jlheig/Code/Server/.idea/.gitignore | 3 + specs/jlheig/Code/Server/.idea/misc.xml | 6 ++ specs/jlheig/Code/Server/.idea/modules.xml | 8 ++ specs/jlheig/Code/Server/.idea/vcs.xml | 6 ++ specs/jlheig/Code/Server/Server.iml | 11 ++ .../Server/out/production/Server/Server.class | Bin 0 -> 4209 bytes specs/jlheig/Code/Server/src/Server.java | 102 ++++++++++++++++++ 15 files changed, 305 insertions(+) create mode 100644 specs/jlheig/Code/.idea/workspace.xml create mode 100644 specs/jlheig/Code/Client/.idea/.gitignore create mode 100644 specs/jlheig/Code/Client/.idea/misc.xml create mode 100644 specs/jlheig/Code/Client/.idea/modules.xml create mode 100644 specs/jlheig/Code/Client/.idea/vcs.xml create mode 100644 specs/jlheig/Code/Client/Client.iml create mode 100644 specs/jlheig/Code/Client/out/production/Client/Client.class create mode 100644 specs/jlheig/Code/Client/src/Client.java create mode 100644 specs/jlheig/Code/Server/.idea/.gitignore create mode 100644 specs/jlheig/Code/Server/.idea/misc.xml create mode 100644 specs/jlheig/Code/Server/.idea/modules.xml create mode 100644 specs/jlheig/Code/Server/.idea/vcs.xml create mode 100644 specs/jlheig/Code/Server/Server.iml create mode 100644 specs/jlheig/Code/Server/out/production/Server/Server.class create mode 100644 specs/jlheig/Code/Server/src/Server.java diff --git a/specs/jlheig/Code/.idea/workspace.xml b/specs/jlheig/Code/.idea/workspace.xml new file mode 100644 index 0000000..eb09126 --- /dev/null +++ b/specs/jlheig/Code/.idea/workspace.xml @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + + + + + + + 1617196724818 + + + + + + + \ No newline at end of file diff --git a/specs/jlheig/Code/Client/.idea/.gitignore b/specs/jlheig/Code/Client/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/specs/jlheig/Code/Client/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/specs/jlheig/Code/Client/.idea/misc.xml b/specs/jlheig/Code/Client/.idea/misc.xml new file mode 100644 index 0000000..e0844bc --- /dev/null +++ b/specs/jlheig/Code/Client/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/specs/jlheig/Code/Client/.idea/modules.xml b/specs/jlheig/Code/Client/.idea/modules.xml new file mode 100644 index 0000000..b7ec2d4 --- /dev/null +++ b/specs/jlheig/Code/Client/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/specs/jlheig/Code/Client/.idea/vcs.xml b/specs/jlheig/Code/Client/.idea/vcs.xml new file mode 100644 index 0000000..4fce1d8 --- /dev/null +++ b/specs/jlheig/Code/Client/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/specs/jlheig/Code/Client/Client.iml b/specs/jlheig/Code/Client/Client.iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/specs/jlheig/Code/Client/Client.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/specs/jlheig/Code/Client/out/production/Client/Client.class b/specs/jlheig/Code/Client/out/production/Client/Client.class new file mode 100644 index 0000000000000000000000000000000000000000..e50266040f590dd10c3ed690f9f7c1298e86e2ed GIT binary patch literal 3148 zcma)8TX)pf75+3cwqzk=d&U@>aFHRVW{fd5q)E9nV8^6RjSV(9anhTZ5k@d0O*9%z zdP|#Yn@gLNTnfD=ZA0%3CLVW{wer}9zW1?zp|4%5Ax*z6jc4SAyH;OxboSn7pYPlI zJ4gE4fBy0zfctSv#|XZx;ww5VoYRp*z6A-`Iv+HjZ@~gC=uqLv+eHnRbQDmO7*}FE z@s(uyq>dT*@>Z5dprZ#x38|>KtfL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Jrd0?QZH}kP6(-{tZ)$ z$JtXM*F_}5HF82^v_?*Ps3AExdKV9Vs7P6K{9cX6NCb39;E_+qz+cfy2@|7nz#WRr}zJ>OV*5+GimGh#+&Tt=9znhjX(w@MV{tGmM+YSH# literal 0 HcmV?d00001 diff --git a/specs/jlheig/Code/Client/src/Client.java b/specs/jlheig/Code/Client/src/Client.java new file mode 100644 index 0000000..2ee2ec0 --- /dev/null +++ b/specs/jlheig/Code/Client/src/Client.java @@ -0,0 +1,89 @@ +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.PrintWriter; +import java.net.Socket; +import java.util.Scanner; +import java.util.logging.Level; +import java.util.logging.Logger; + +public class Client { + public static void main(String[] args) throws IOException { + Client client = new Client(); + Scanner scan = new Scanner(System.in); + + if(args.length == 0){ + System.out.println("Error, we need 1 argument to serve as the server adress"); + return; + } + + String server = args[0]; + client.connect(server, PORT); + String input; + do{ + input = scan.nextLine(); + + if(input.compareTo(QUIT) == 0){ + client.isConnected = false; + } + + client.writer.println(input); + + }while(!client.isConnected); + + client.disconnect(); + } + + public static String QUIT = "QUIT"; + public static int PORT = 3334; + + private Logger logger = Logger.getLogger(Client.class.getName()); + + Socket clientSocket; + PrintWriter writer; + BufferedReader reader; + boolean isConnected; + + public void connect(String server, int port) throws IOException{ + try{ + clientSocket = new Socket(server, port); + writer = new PrintWriter(clientSocket.getOutputStream()); + reader = new BufferedReader(new InputStreamReader(clientSocket.getInputStream())); + isConnected = true; + } + catch (IOException e){ + logger.log(Level.SEVERE, "Impossible to connect to the server, server not found", e.getMessage()); + } + + listener(); + } + + public void disconnect() throws IOException{ + try { + if (isConnected) { + logger.log(Level.INFO, "Client wants to quit"); + isConnected = false; + writer.close(); + reader.close(); + clientSocket.close(); + } + } + catch (IOException e){ + logger.log(Level.SEVERE, "Error while disconnecting", e.getMessage()); + } + } + + public void listener(){ + try{ + String resp; + resp = reader.readLine(); + while(isConnected && (resp != null)){ + System.out.println(resp); + } + } + catch (IOException e){ + logger.log(Level.SEVERE, "Error while listening", e.getMessage()); + } + } + +} diff --git a/specs/jlheig/Code/Server/.idea/.gitignore b/specs/jlheig/Code/Server/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/specs/jlheig/Code/Server/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/specs/jlheig/Code/Server/.idea/misc.xml b/specs/jlheig/Code/Server/.idea/misc.xml new file mode 100644 index 0000000..e0844bc --- /dev/null +++ b/specs/jlheig/Code/Server/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/specs/jlheig/Code/Server/.idea/modules.xml b/specs/jlheig/Code/Server/.idea/modules.xml new file mode 100644 index 0000000..7ec00e1 --- /dev/null +++ b/specs/jlheig/Code/Server/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/specs/jlheig/Code/Server/.idea/vcs.xml b/specs/jlheig/Code/Server/.idea/vcs.xml new file mode 100644 index 0000000..4fce1d8 --- /dev/null +++ b/specs/jlheig/Code/Server/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/specs/jlheig/Code/Server/Server.iml b/specs/jlheig/Code/Server/Server.iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/specs/jlheig/Code/Server/Server.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/specs/jlheig/Code/Server/out/production/Server/Server.class b/specs/jlheig/Code/Server/out/production/Server/Server.class new file mode 100644 index 0000000000000000000000000000000000000000..a594f369bbbc5749f38ee76b11eee5d1d5d75cae GIT binary patch literal 4209 zcmaJ^Yj_k_8GcW)*_jMW6BZI!2z0Pe0t5m9(l!A~$ORS?NLc~}dSTcM$&$&=GCNBe zTdlQdRjk^2Yt&Y>YP4!A1d|pj7OPa-dcW6u{pBD3_(LB=>U(A;+0EsVeK?oz`_6Zp z?|aY5tJg1F0&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Q-H zAXQh6Vg48vG=wf9M%qG2TQr8MF)VHRD&!e`!G^Uhz3r%WU=V_~mg(^xbv?CX=UWQ3ihGfaPR*o=Q+3;x4Sx`rlEjAju=iyy zO4wLxc6bEgXu}BBMH@#@7u`I94bd$l*eD@Kcv!JSMoF+K zVWu=HFXyiUbNFX_6gOfnW3$OGLI!{2tnt+E@n`&jwel|R=aK&)Y47&N_j= Date: Wed, 31 Mar 2021 19:12:11 +0200 Subject: [PATCH 3/3] Correction, now works perfectly! Even added a DIV and HELP command --- .../production/Client/Client$listener.class | Bin 0 -> 1284 bytes .../Client/out/production/Client/Client.class | Bin 3148 -> 3143 bytes specs/jlheig/Code/Client/src/Client.java | 37 +++++++++-------- .../Server/out/production/Server/Server.class | Bin 4209 -> 4503 bytes specs/jlheig/Code/Server/src/Server.java | 39 +++++++++++------- 5 files changed, 44 insertions(+), 32 deletions(-) create mode 100644 specs/jlheig/Code/Client/out/production/Client/Client$listener.class diff --git a/specs/jlheig/Code/Client/out/production/Client/Client$listener.class b/specs/jlheig/Code/Client/out/production/Client/Client$listener.class new file mode 100644 index 0000000000000000000000000000000000000000..8fc8368c358b605599187f59ab28bdb7f2f9ca67 GIT binary patch literal 1284 zcmZux*;dm~6y2fNv>|1l5vhPs1}V-1ibySjmciClhqq8JB^Z*fBt`uczra^vDX!&% zk3RSneu=toQln=#zd5W{Va!FN^MQ*mF#jDo1YWqQNY3Szm8WeVGu*aOox{aFPKsY7tA zsGvUMYzPHSInx#^)tz6WLQPRHRZVm*2~09Ynh%eY~d=H@Sz7QN8GB-H5HU|g;$Zuw~bvRZ5ehsUGQDgF4Iq8)sE0$I_ag=?1z%5_@-mi zmMHi}>D{tXsS(i%PSq`m1yfRO2%DUeIZ19sc>bc}`6?dhXhExvHuURwh*=$vFsI_N zj(KEMJkgQGf{Ld)7O|wDEg*HewvK0bt|F&n87t(MbzR3zzTaZuWY{Cg>sXcf)^xl; zo??c4jx11)<9jUWrpLV2_zil%vcdgKHMg7&QO}0<(=bu zuH&x_?L<5HHOsR^wDE~=P{zNbZZGiZ`0gKWG4xQPB*t}m!Z zgtpB1S14Z*`Gkw%SN#DlyvhASVjt0o1E`<>{rQZ6<w(Y2?<5MA+i^g z9^yYrj436VOHjGy(Srhp@P?KmM)3;w@tUvZZ9p;^_$KH(!1z&8P2zGuJX0e+$Q*If d9Gq7X>!bS+fjSK1O0bWhm%GN`Mi%G+{sY4jEFAy< literal 0 HcmV?d00001 diff --git a/specs/jlheig/Code/Client/out/production/Client/Client.class b/specs/jlheig/Code/Client/out/production/Client/Client.class index e50266040f590dd10c3ed690f9f7c1298e86e2ed..525ff31193bd316cb3bf864b34ba6446d40f4649 100644 GIT binary patch delta 1650 zcmY+FS#%R+6vuxvlVm2tw6tmI0tH%HAWdn@T6Qh1P|#8l5s3>L$NjZnKAb z)aZoGY_iJSt3vKGx!wnFO`b7%)~1!`Y@$4`%nK^)MGH?wyri<8QCY;)a>n9ii!~;%XjrMiY|c$r zx)}{;TRQD#dQ*vP*3FLod`c@X%jOa%dWU3rf6h&MhxOUotKMmSzxSKo+@&#Nz|H2i zyGQo9nXJPW`ZPklsX;fLGdb%p!a0-I9A4)QhYf6WxQ5MMw^38^ro&sjt&Y6o@GkFp z2aF9J?>l_Jd53kZcesUH9X{lo!y48)e8k5N-E4CBgg%Em=<~ies;w<5>ME}GelhB- zPx(w`{M>T_tINLNf|`sv^w8_=2-Jng9LAZ@X!ecO8PV7s$#hsvVpUHU>W_O+@ z>HR8^r-`ljkdduu60a*_#iM8_dSR*P1$WU4=i-BCQhlG;tuosx=QQy(u>x8wqWc&Z z2}}}<8Iy!YWk+Y5*m4Z9qRap>D(K`|nL4GTTt~mm!faR%E#VM40HvS_*AS5)(6L^^ofiRGP(k76I9g) zeX83UWaKkzR$%1MAKH9sRDDLVz8)$(J3K#M!&2($Vvb;M5S7iBq8i!70^+oAI}3}2 zUsWoO>)9b0EOv8)K+vcXC_A}PKr9q)cgbT&z7B2@<^qy6Dv@i2!JFk&9m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S>z zG86LRfL++blb$?z{zraCua2gQ|Ip>DE3&=B3&j-iEYSu|Vp#!nYham+XjIzAM9@Wy zq0z;121?LIdV__^=D-T}Q|J|_wV`8JD+rail*!VVjt%EJ>r0e?F z)~wL0CYH`3J)sgW(vv4bvr!>_jKE7qDS=z(5u5&gy-J0(hUt(Zc=QJuR%SxwFCT~N_zm39!ZK3xg%-qYo2lxF0q`D;P diff --git a/specs/jlheig/Code/Client/src/Client.java b/specs/jlheig/Code/Client/src/Client.java index 2ee2ec0..e025d81 100644 --- a/specs/jlheig/Code/Client/src/Client.java +++ b/specs/jlheig/Code/Client/src/Client.java @@ -19,30 +19,32 @@ public static void main(String[] args) throws IOException { String server = args[0]; client.connect(server, PORT); + boolean stayConnected = true; String input; do{ input = scan.nextLine(); if(input.compareTo(QUIT) == 0){ - client.isConnected = false; + stayConnected = false; } client.writer.println(input); + client.writer.flush(); - }while(!client.isConnected); + }while(stayConnected); client.disconnect(); } - public static String QUIT = "QUIT"; - public static int PORT = 3334; + private static String QUIT = "QUIT"; + private static int PORT = 3334; private Logger logger = Logger.getLogger(Client.class.getName()); Socket clientSocket; PrintWriter writer; BufferedReader reader; - boolean isConnected; + boolean isConnected = false; public void connect(String server, int port) throws IOException{ try{ @@ -52,13 +54,13 @@ public void connect(String server, int port) throws IOException{ isConnected = true; } catch (IOException e){ - logger.log(Level.SEVERE, "Impossible to connect to the server, server not found", e.getMessage()); + logger.log(Level.SEVERE, "Impossible to connect to the server", e.getMessage()); } - listener(); + new Thread(new listener()).start(); } - public void disconnect() throws IOException{ + public void disconnect() throws IOException { try { if (isConnected) { logger.log(Level.INFO, "Client wants to quit"); @@ -73,17 +75,18 @@ public void disconnect() throws IOException{ } } - public void listener(){ - try{ + class listener implements Runnable { + public void run(){ String resp; - resp = reader.readLine(); - while(isConnected && (resp != null)){ - System.out.println(resp); + try{ + while((isConnected && (resp = reader.readLine()) != null)){ + System.out.println(resp); + } + } + catch (IOException e){ + logger.log(Level.SEVERE, "Error while listening", e.getMessage()); + isConnected = false; } - } - catch (IOException e){ - logger.log(Level.SEVERE, "Error while listening", e.getMessage()); } } - } diff --git a/specs/jlheig/Code/Server/out/production/Server/Server.class b/specs/jlheig/Code/Server/out/production/Server/Server.class index a594f369bbbc5749f38ee76b11eee5d1d5d75cae..e95da33b284f28d14ed11d820c416fff87255e17 100644 GIT binary patch delta 2133 zcmaKseSDi$7017~O>&<+dB#RYs%iHUS-Th3wXCiiW|Y0PZtd1>uu=Ag5Zh;Mwl1k@ zRuIJ?z953&d~^d89VqK2f^KmswlbMcP?QZt5P>P8I1v@~4?jA!dhXMGKIOw7CZGJy z`?=?w+;jh$*f*o_e$EJeM*u?NOpVfTMC<}XSs@P{! z$z2wA8|$qG?lGFrTYSML$GxVCFBfB2MzZ%0}mN^So3vTTK-0qY2_TTC|Z2eVueME#VU(di#ChZnxmeh{-sKuRn}as zT*dS?J5mFw`rcHgyM9?No$uM@=F^=m*LS*o`E)k3*lR0$cEXV65zV(W!J8b>oo?RY-K=z2!-&JTdDP(;-|_a8Pj7pS<8O{> zmB0ndy1H_1f4}Ct4&UR1V$$+#Hs7DmrTW_4d{4Hke`1L5TRiUY1V7OH(BVmb+>TsG64XkDL3jV1Fc1054ia>~^3w1J;^HwG3>_$kjA;b#V(^^OOURnO7x z@N=G5sD#5Wc)?)>%?>Z}l6QXars@`&74a3l+5WT~kneF5o!Lyr?KESmtE+Q3O}lqA zc=5VlI{b>499Ge6@vAP*&Laaa5gd|pUR)^Q<;HJrG1~u1biw(5E_up zlA9#B*4q=Qn6*xHA(4z_y`basK`!SCk-}_Xqulki-pNR!V0_I=n+Qw3#=pXsCvqhn zB3V+|RT8P#?p-%s+^@tvrI);t{hs_WLByQR;j79su{GYT2`w@c@CGdR$ak*bv2i(Y=I5x z1~#hO=}`OFqz=L!Du#dYxYN zhO}Vr`5l}`jTE$vtK}x2kXGL#`(#PJiCn|AM5L7aNcp;2?xOHsS;w%{btj#|*$jz8 zmn?}k7yjIOMbxXZF0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