Commit ee7f03fd authored by mahdikarami0111's avatar mahdikarami0111

initial commit

parents
Pipeline #6035 canceled 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.2.iml" filepath="$PROJECT_DIR$/APW_S10.2.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"?>
<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 s = new Socket("localhost",8081);
BufferedReader reader = new BufferedReader(new InputStreamReader(s.getInputStream()));
PrintWriter writer = new PrintWriter(s.getOutputStream(),true);
BufferedReader keyboard = new BufferedReader(new InputStreamReader(System.in));
while (true){
String message = keyboard.readLine();
if(message.toUpperCase().equals("OVER")){
writer.println(message);
while (true){
message = reader.readLine();
if(message.equals("finished")){
break;
}
System.out.println(message);
}
reader.close();
writer.close();
break;
}
writer.println(message);
System.out.println(reader.readLine());
}
}catch (IOException e){
e.printStackTrace();
}
}
}
package com.company;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;
import java.security.PrivateKey;
import java.util.ArrayList;
public class ClientHandler extends Thread{
private BufferedReader reader;
private PrintWriter writer;
private Socket s;
private ArrayList<String> messages;
public ClientHandler(Socket s){
try {
this.s = s;
messages = new ArrayList<>();
reader = new BufferedReader(new InputStreamReader(s.getInputStream()));
writer = new PrintWriter(s.getOutputStream(),true);
}catch (IOException e){
e.printStackTrace();
}
}
@Override
public void run(){
try {
while (true){
String message = reader.readLine();
if(message.toUpperCase().equals("OVER")){
for (String m : messages){
writer.println(m);
}
writer.println("finished");
reader.close();
writer.close();
s.close();
break;
}
messages.add(message);
writer.println("[Server] received your message : "+message);
}
}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.IOException;
import java.net.ServerSocket;
public class Server {
public static void main(String[] args) {
try {
ServerSocket ss = new ServerSocket(8081);
while (true){
ClientHandler clientHandler = new ClientHandler(ss.accept());
clientHandler.start();
}
}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