Commit 94fc31c7 authored by mohammad.salama's avatar mohammad.salama

Initial commit

parents
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/
### IntelliJ IDEA ###
.idea/modules.xml
.idea/jarRepositories.xml
.idea/compiler.xml
.idea/libraries/
*.iws
*.iml
*.ipr
### Eclipse ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/
### VS Code ###
.vscode/
### Mac OS ###
.DS_Store
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding">
<file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/src/main/resources" charset="UTF-8" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="MavenProjectsManager">
<option name="originalFiles">
<list>
<option value="$PROJECT_DIR$/pom.xml" />
</list>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" 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="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="AutoImportSettings">
<option name="autoReloadType" value="SELECTIVE" />
</component>
<component name="ChangeListManager">
<list default="true" id="71bec43c-ef6e-431f-a77c-2b7f124f5fea" name="Changes" comment="">
<change afterPath="$PROJECT_DIR$/.gitignore" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/encodings.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/misc.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/vcs.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/pom.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/java/ChatClient.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/java/IServerChat.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/java/org/example/Main.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="Interface" />
<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="2XxxNy2avODxT8GBKoqxsQKeVEN" />
<component name="ProjectLevelVcsManager" settingsEditedManually="true">
<ConfirmationsSetting value="2" id="Add" />
</component>
<component name="ProjectViewState">
<option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" />
</component>
<component name="PropertiesComponent"><![CDATA[{
"keyToString": {
"RunOnceActivity.OpenProjectViewOnStart": "true",
"RunOnceActivity.ShowReadmeOnStart": "true",
"SHARE_PROJECT_CONFIGURATION_FILES": "true",
"last_opened_file_path": "D:/HIAST/FIY/FS/Distributed Systems/Lab/3/HW/ChatClient"
}
}]]></component>
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
<component name="TaskManager">
<task active="true" id="Default" summary="Default task">
<changelist id="71bec43c-ef6e-431f-a77c-2b7f124f5fea" name="Changes" comment="" />
<created>1699584495345</created>
<option name="number" value="Default" />
<option name="presentableId" value="Default" />
<updated>1699584495345</updated>
</task>
<servers />
</component>
<component name="Vcs.Log.Tabs.Properties">
<option name="TAB_STATES">
<map>
<entry key="MAIN">
<value>
<State />
</value>
</entry>
</map>
</option>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>ChatClient</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>
\ No newline at end of file
import com.sun.org.apache.xerces.internal.impl.xpath.XPath;
import java.net.MalformedURLException;
import java.rmi.Naming;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
public class ChatClient
{
public static void main(String[] args) throws MalformedURLException, NotBoundException, RemoteException {
String loc = "localhost";
IServerChat iServerChat = (IServerChat) Naming.lookup("rmi://"+loc+":1099/chat");
String fname = "MM";
String lname = "SS";
String username = "ms";
String password = "123";
iServerChat.Register(fname , lname , username , password);
iServerChat.createChatRoom("room1" , username);
iServerChat.LogIn(username , password);
iServerChat.createChatRoom("room2" ,username);
iServerChat.createChatRoom("room3" , username);
iServerChat.deleteChatRoom("room2", username);
iServerChat.LogOut(username , password);
}
}
import java.rmi.Remote;
import java.rmi.RemoteException;
import java.util.List;
public interface IServerChat extends Remote
{
public void createChatRoom(String roomName , String userName) throws RemoteException;
///public void joinChatRoom(String roomName) throws RemoteException;
public void deleteChatRoom(String roomName , String userName) throws RemoteException;
public void Register(String fname , String lname, String username, String password) throws RemoteException;
public void LogIn(String username, String password) throws RemoteException;
/// public List<String> getChatRooms(String username , String password) throws RemoteException;
/// public List<String> getConversation(String roomName , String username , String password) throws RemoteException;
// public void sendMessage(String roomName, String message , String username , String password ) throws RemoteException;
public void LogOut(String username , String Password) throws RemoteException;
/// public void addListener (String roomName ) throws RemoteException;
}
package org.example;
public class Main {
public static void main(String[] args) {
System.out.println("Hello world!");
}
}
\ No newline at end of file
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/
### IntelliJ IDEA ###
.idea/modules.xml
.idea/jarRepositories.xml
.idea/compiler.xml
.idea/libraries/
*.iws
*.iml
*.ipr
### Eclipse ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/
### VS Code ###
.vscode/
### Mac OS ###
.DS_Store
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding">
<file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/src/main/resources" charset="UTF-8" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="MavenProjectsManager">
<option name="originalFiles">
<list>
<option value="$PROJECT_DIR$/pom.xml" />
</list>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" 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="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="AutoImportSettings">
<option name="autoReloadType" value="SELECTIVE" />
</component>
<component name="ChangeListManager">
<list default="true" id="23a09f69-45e8-4607-a94c-253a284a386d" name="Changes" comment="ChatServiceFirst5">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" 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="Interface" />
<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="2XxxKvXjI03nFIEcqB1p5z0EbuK" />
<component name="ProjectLevelVcsManager" settingsEditedManually="true">
<ConfirmationsSetting value="2" id="Add" />
</component>
<component name="ProjectViewState">
<option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" />
</component>
<component name="PropertiesComponent"><![CDATA[{
"keyToString": {
"RunOnceActivity.OpenProjectViewOnStart": "true",
"RunOnceActivity.ShowReadmeOnStart": "true",
"SHARE_PROJECT_CONFIGURATION_FILES": "true",
"last_opened_file_path": "D:/HIAST/FIY/FS/Distributed Systems/Lab/3/HW/ChatClient"
}
}]]></component>
<component name="RecentsManager">
<key name="CopyFile.RECENT_KEYS">
<recent name="D:\HIAST\FIY\FS\Distributed Systems\Lab\3\ChatServer" />
</key>
</component>
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
<component name="TaskManager">
<task active="true" id="Default" summary="Default task">
<changelist id="23a09f69-45e8-4607-a94c-253a284a386d" name="Changes" comment="" />
<created>1699584476389</created>
<option name="number" value="Default" />
<option name="presentableId" value="Default" />
<updated>1699584476389</updated>
</task>
<task id="LOCAL-00001" summary="ChatServiceFirst5">
<created>1699587355382</created>
<option name="number" value="00001" />
<option name="presentableId" value="LOCAL-00001" />
<option name="project" value="LOCAL" />
<updated>1699587355382</updated>
</task>
<option name="localTasksCounter" value="2" />
<servers />
</component>
<component name="Vcs.Log.Tabs.Properties">
<option name="TAB_STATES">
<map>
<entry key="MAIN">
<value>
<State />
</value>
</entry>
</map>
</option>
</component>
<component name="VcsManagerConfiguration">
<MESSAGE value="ChatServiceFirst5" />
<option name="LAST_COMMIT_MESSAGE" value="ChatServiceFirst5" />
</component>
</project>
\ No newline at end of file
grant
{
permission java.security.AllPermission;
};
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>ChatServer</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>
\ No newline at end of file
import java.rmi.RMISecurityManager;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
public class ChatServer
{
public static void main(String[] args) throws RemoteException
{
System.setProperty("java.security.policy" , "./RmiPolicy.policy");
System.setSecurityManager(new RMISecurityManager());
Registry registry = LocateRegistry.createRegistry(1099);
ServerChatImp serverChatImp = new ServerChatImp();
String service = "chat";
registry.rebind(service , serverChatImp);
}
}
import java.rmi.Remote;
import java.rmi.RemoteException;
import java.util.List;
public interface IServerChat extends Remote
{
public void createChatRoom(String roomName , String userName) throws RemoteException;
///public void joinChatRoom(String roomName) throws RemoteException;
public void deleteChatRoom(String roomName , String userName) throws RemoteException;
public void Register(String fname , String lname, String username, String password) throws RemoteException;
public void LogIn(String username, String password) throws RemoteException;
/// public List<String> getChatRooms(String username , String password) throws RemoteException;
/// public List<String> getConversation(String roomName , String username , String password) throws RemoteException;
// public void sendMessage(String roomName, String message , String username , String password ) throws RemoteException;
public void LogOut(String username , String Password) throws RemoteException;
/// public void addListener (String roomName ) throws RemoteException;
}
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class ServerChatImp extends UnicastRemoteObject implements IServerChat
{
Map<String , UsersDB> users = new HashMap<>();
Map<UsersDB , List<String>> ChatRooms = new HashMap<>();
Map<UsersDB , Boolean> ActiveUsers = new HashMap<>();
protected ServerChatImp() throws RemoteException
{
}
@Override
public void createChatRoom(String roomName, String userName) throws RemoteException
{
if (!users.containsKey(userName)) return;
UsersDB usersDB = users.get(userName);
ChatRooms.get(usersDB).add(roomName);
System.out.println("User : " + userName + " -- now has the following chat rooms");
for (String str : ChatRooms.get(usersDB))
{
System.out.println(str);
}
System.out.println("*****************************");
}
@Override
public void deleteChatRoom(String roomName, String userName) throws RemoteException
{
if (!users.containsKey(userName))
{
System.out.println("No Such User");
return;
}
UsersDB usersDB = users.get(userName);
if (ChatRooms.get(usersDB).contains(roomName)) {
ChatRooms.get(usersDB).remove(roomName);
System.out.println("User : " + userName + " -- now has the following chat rooms");
for (String str : ChatRooms.get(usersDB)) {
System.out.println(str);
}
System.out.println("*****************************");
}
else System.out.println("No Such Room for " + userName);
}
@Override
public void Register(String fname, String lname, String username, String password) throws RemoteException
{
UsersDB usersDB = new UsersDB(fname , lname , username , password);
users.put(username , usersDB);
ChatRooms.put(usersDB , new ArrayList<>());
}
@Override
public void LogIn(String username, String password) throws RemoteException
{
if (!users.containsKey(username)) return;
/*
validation and authentication for later
* */
UsersDB usersDB = users.get(username);
if (usersDB.checkPassword(password)) ActiveUsers.put(usersDB, true);
}
@Override
public void LogOut(String username, String Password) throws RemoteException
{
if (!users.containsKey(username)) return;
UsersDB usersDB = users.get(username);
ActiveUsers.put(usersDB, false);
}
}
public class UsersDB
{
private String firstName, lastName, userName,password;
public UsersDB(String firstName , String lastName , String userName , String password)
{
this.lastName = lastName;
this.userName = userName;
this.firstName = firstName;
this.password = password;
}
public boolean checkPassword(String password)
{
return this.password.equals(password);
}
}
package org.example;
public class Main {
public static void main(String[] args) {
System.out.println("Hello world!");
}
}
\ No newline at end of file
git config --global user.name "mohammad.salama"
git config --global user.email "mohammad.salama@hiast.edu.sy"
git init
git remote add origin git@git.hiast.edu.sy:mohammad.salama/testdirs.git
git add .
git commit -m "Initial commit"
git push -u origin master
\ No newline at end of file
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