Commit cab3627a authored by mahdikarami0111's avatar mahdikarami0111

initial commit

parents
Pipeline #6010 failed with stages
# Default ignored files
/shelf/
/workspace.xml
<html>Simple <b>Java</b> application that includes a class with <code>main()</code> method</html>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding">
<file url="PROJECT" charset="UTF-8" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectKey">
<option name="state" value="project://e2804f05-5315-4fc6-a121-c522a6c26470" />
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_15" default="true" project-jdk-name="15" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/APW-S10.iml" filepath="$PROJECT_DIR$/APW-S10.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<template>
<input-field default="com.company">IJ_BASE_PACKAGE</input-field>
</template>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
</component>
</project>
\ No newline at end of file
<?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>
\ No newline at end of file
package com.company;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;
public class Client {
public static void main(String[] args) {
try {
Socket client = new Socket("localhost",8080);
BufferedReader reader = new BufferedReader(new InputStreamReader(client.getInputStream()));
BufferedReader keyboard = new BufferedReader(new InputStreamReader(System.in));
PrintWriter writer = new PrintWriter(client.getOutputStream(),true);
while (true){
String request = keyboard.readLine();
writer.println(request);
if(request.toLowerCase().equals("over")){
while (true){
request = reader.readLine();
if(request == null){
break;
}
System.out.println(request);
}
reader.close();
writer.close();
keyboard.close();
client.close();
break;
}
String answer = reader.readLine();
System.out.println(answer);
}
}catch (IOException e){
e.printStackTrace();
}
}
}
package com.company;
public class Main {
public static void main(String[] args) {
// write your code here
}
}
package com.company;
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.ArrayList;
public class Server {
private static ArrayList<String> messages;
public static void main(String[] args) {
messages = new ArrayList<>();
try {
ServerSocket server = new ServerSocket(8080);
System.out.println("Waiting for clients to join ...");
Socket client = server.accept();
System.out.println("A client joined");
BufferedReader reader = new BufferedReader(new InputStreamReader(client.getInputStream()));
PrintWriter writer = new PrintWriter(client.getOutputStream(),true);
while (true){
String request = reader.readLine();
writer.println("[Server] received your message : "+request);
messages.add(request);
if(request.toLowerCase().equals("over")){
writer.println("Your sent messages are :");
for(int i = 0 ; i < messages.size() ; i++){
writer.println(messages.get(i));
}
reader.close();
writer.close();
System.out.println("Server is shutting down...");
server.close();
break;
}
}
}catch (IOException e){
e.printStackTrace();
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment