Golfier
parent
17154ce6f3
commit
b714a69445
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="PYTHON_MODULE" version="4">
|
||||
<component name="NewModuleRootManager">
|
||||
<content url="file://$MODULE_DIR$" />
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
@ -0,0 +1,12 @@
|
||||
<component name="InspectionProjectProfileManager">
|
||||
<profile version="1.0">
|
||||
<option name="myName" value="Project Default" />
|
||||
<inspection_tool class="PyUnresolvedReferencesInspection" enabled="true" level="WARNING" enabled_by_default="true">
|
||||
<option name="ignoredIdentifiers">
|
||||
<list>
|
||||
<option value="main.helloHandler.*" />
|
||||
</list>
|
||||
</option>
|
||||
</inspection_tool>
|
||||
</profile>
|
||||
</component>
|
@ -0,0 +1,6 @@
|
||||
<component name="InspectionProjectProfileManager">
|
||||
<settings>
|
||||
<option name="USE_PROJECT_PROFILE" value="false" />
|
||||
<version value="1.0" />
|
||||
</settings>
|
||||
</component>
|
@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.8" project-jdk-type="Python SDK" />
|
||||
</project>
|
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/ServerPyt.iml" filepath="$PROJECT_DIR$/.idea/ServerPyt.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
|
||||
</component>
|
||||
</project>
|
@ -0,0 +1,140 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="BranchesTreeState">
|
||||
<expand>
|
||||
<path>
|
||||
<item name="ROOT" type="e8cecc67:BranchNodeDescriptor" />
|
||||
<item name="LOCAL_ROOT" type="e8cecc67:BranchNodeDescriptor" />
|
||||
</path>
|
||||
</expand>
|
||||
<select />
|
||||
</component>
|
||||
<component name="ChangeListManager">
|
||||
<list default="true" id="28254644-08db-40a1-8497-05ce7fa43f93" name="Default Changelist" comment="" />
|
||||
<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="Git.Settings">
|
||||
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$/.." />
|
||||
</component>
|
||||
<component name="ProjectId" id="1kKwlpoG7vbAj2OMN8ReQMzKG2s" />
|
||||
<component name="ProjectLevelVcsManager" settingsEditedManually="true" />
|
||||
<component name="ProjectViewState">
|
||||
<option name="hideEmptyMiddlePackages" value="true" />
|
||||
<option name="showLibraryContents" value="true" />
|
||||
</component>
|
||||
<component name="PropertiesComponent">
|
||||
<property name="RunOnceActivity.OpenProjectViewOnStart" value="true" />
|
||||
<property name="last_opened_file_path" value="$PROJECT_DIR$" />
|
||||
<property name="restartRequiresConfirmation" value="false" />
|
||||
</component>
|
||||
<component name="RunManager" selected="Python.server">
|
||||
<configuration name="client" type="PythonConfigurationType" factoryName="Python" temporary="true" nameIsGenerated="true">
|
||||
<module name="ServerPyt" />
|
||||
<option name="INTERPRETER_OPTIONS" value="" />
|
||||
<option name="PARENT_ENVS" value="true" />
|
||||
<envs>
|
||||
<env name="PYTHONUNBUFFERED" value="1" />
|
||||
</envs>
|
||||
<option name="SDK_HOME" value="" />
|
||||
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$" />
|
||||
<option name="IS_MODULE_SDK" value="true" />
|
||||
<option name="ADD_CONTENT_ROOTS" value="true" />
|
||||
<option name="ADD_SOURCE_ROOTS" value="true" />
|
||||
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/client.py" />
|
||||
<option name="PARAMETERS" value="" />
|
||||
<option name="SHOW_COMMAND_LINE" value="false" />
|
||||
<option name="EMULATE_TERMINAL" value="false" />
|
||||
<option name="MODULE_MODE" value="false" />
|
||||
<option name="REDIRECT_INPUT" value="false" />
|
||||
<option name="INPUT_FILE" value="" />
|
||||
<method v="2" />
|
||||
</configuration>
|
||||
<configuration name="server" type="PythonConfigurationType" factoryName="Python" temporary="true" nameIsGenerated="true">
|
||||
<module name="ServerPyt" />
|
||||
<option name="INTERPRETER_OPTIONS" value="" />
|
||||
<option name="PARENT_ENVS" value="true" />
|
||||
<envs>
|
||||
<env name="PYTHONUNBUFFERED" value="1" />
|
||||
</envs>
|
||||
<option name="SDK_HOME" value="" />
|
||||
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$" />
|
||||
<option name="IS_MODULE_SDK" value="true" />
|
||||
<option name="ADD_CONTENT_ROOTS" value="true" />
|
||||
<option name="ADD_SOURCE_ROOTS" value="true" />
|
||||
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/server.py" />
|
||||
<option name="PARAMETERS" value="" />
|
||||
<option name="SHOW_COMMAND_LINE" value="false" />
|
||||
<option name="EMULATE_TERMINAL" value="false" />
|
||||
<option name="MODULE_MODE" value="false" />
|
||||
<option name="REDIRECT_INPUT" value="false" />
|
||||
<option name="INPUT_FILE" value="" />
|
||||
<method v="2" />
|
||||
</configuration>
|
||||
<recent_temporary>
|
||||
<list>
|
||||
<item itemvalue="Python.server" />
|
||||
<item itemvalue="Python.client" />
|
||||
</list>
|
||||
</recent_temporary>
|
||||
</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="28254644-08db-40a1-8497-05ce7fa43f93" name="Default Changelist" comment="" />
|
||||
<created>1605462744659</created>
|
||||
<option name="number" value="Default" />
|
||||
<option name="presentableId" value="Default" />
|
||||
<updated>1605462744659</updated>
|
||||
</task>
|
||||
<servers />
|
||||
</component>
|
||||
<component name="Vcs.Log.Tabs.Properties">
|
||||
<option name="TAB_STATES">
|
||||
<map>
|
||||
<entry key="MAIN">
|
||||
<value>
|
||||
<State />
|
||||
</value>
|
||||
</entry>
|
||||
</map>
|
||||
</option>
|
||||
<option name="oldMeFiltersMigrated" value="true" />
|
||||
</component>
|
||||
<component name="WindowStateProjectService">
|
||||
<state width="1899" height="281" key="GridCell.Tab.0.bottom" timestamp="1605469519241">
|
||||
<screen x="0" y="0" width="1920" height="1040" />
|
||||
</state>
|
||||
<state width="1899" height="281" key="GridCell.Tab.0.bottom/0.0.1920.1040@0.0.1920.1040" timestamp="1605469519241" />
|
||||
<state width="1899" height="281" key="GridCell.Tab.0.center" timestamp="1605469519241">
|
||||
<screen x="0" y="0" width="1920" height="1040" />
|
||||
</state>
|
||||
<state width="1899" height="281" key="GridCell.Tab.0.center/0.0.1920.1040@0.0.1920.1040" timestamp="1605469519241" />
|
||||
<state width="1899" height="281" key="GridCell.Tab.0.left" timestamp="1605469519241">
|
||||
<screen x="0" y="0" width="1920" height="1040" />
|
||||
</state>
|
||||
<state width="1899" height="281" key="GridCell.Tab.0.left/0.0.1920.1040@0.0.1920.1040" timestamp="1605469519241" />
|
||||
<state width="1899" height="281" key="GridCell.Tab.0.right" timestamp="1605469519241">
|
||||
<screen x="0" y="0" width="1920" height="1040" />
|
||||
</state>
|
||||
<state width="1899" height="281" key="GridCell.Tab.0.right/0.0.1920.1040@0.0.1920.1040" timestamp="1605469519241" />
|
||||
<state width="1899" height="348" key="GridCell.Tab.1.bottom" timestamp="1605463596920">
|
||||
<screen x="0" y="0" width="1920" height="1040" />
|
||||
</state>
|
||||
<state width="1899" height="348" key="GridCell.Tab.1.bottom/0.0.1920.1040@0.0.1920.1040" timestamp="1605463596920" />
|
||||
<state width="1899" height="348" key="GridCell.Tab.1.center" timestamp="1605463596920">
|
||||
<screen x="0" y="0" width="1920" height="1040" />
|
||||
</state>
|
||||
<state width="1899" height="348" key="GridCell.Tab.1.center/0.0.1920.1040@0.0.1920.1040" timestamp="1605463596920" />
|
||||
<state width="1899" height="348" key="GridCell.Tab.1.left" timestamp="1605463596920">
|
||||
<screen x="0" y="0" width="1920" height="1040" />
|
||||
</state>
|
||||
<state width="1899" height="348" key="GridCell.Tab.1.left/0.0.1920.1040@0.0.1920.1040" timestamp="1605463596920" />
|
||||
<state width="1899" height="348" key="GridCell.Tab.1.right" timestamp="1605463596920">
|
||||
<screen x="0" y="0" width="1920" height="1040" />
|
||||
</state>
|
||||
<state width="1899" height="348" key="GridCell.Tab.1.right/0.0.1920.1040@0.0.1920.1040" timestamp="1605463596920" />
|
||||
</component>
|
||||
</project>
|
@ -0,0 +1,40 @@
|
||||
import socket
|
||||
import threading
|
||||
|
||||
class Client:
|
||||
def __init__(self):
|
||||
self.create_connection()
|
||||
|
||||
def create_connection(self):
|
||||
self.s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
|
||||
|
||||
while 1:
|
||||
try:
|
||||
host = input("Entrez l'adresse IP de l'Host : ")
|
||||
port = int(input("Entrez le port : "))
|
||||
self.s.connect((host,port))
|
||||
|
||||
break
|
||||
except:
|
||||
print("Impossible de se connecter au serveur")
|
||||
|
||||
self.username = input('Entrez votre pseudo : ')
|
||||
self.s.send(self.username.encode())
|
||||
|
||||
message_handler = threading.Thread(target=self.handle_messages,args=())
|
||||
message_handler.start()
|
||||
|
||||
input_handler = threading.Thread(target=self.input_handler,args=())
|
||||
input_handler.start()
|
||||
|
||||
def handle_messages(self):
|
||||
while 1:
|
||||
print(self.s.recv(1204).decode())
|
||||
print("")
|
||||
|
||||
def input_handler(self):
|
||||
while 1:
|
||||
print("Message : ",end='')
|
||||
self.s.send((self.username+' - '+input()).encode())
|
||||
|
||||
client = Client()
|
@ -0,0 +1,62 @@
|
||||
import socket
|
||||
import threading
|
||||
|
||||
class Server:
|
||||
def __init__(self):
|
||||
self.start_server()
|
||||
|
||||
def start_server(self):
|
||||
self.s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
|
||||
|
||||
host = socket.gethostbyname(socket.gethostname())
|
||||
port = int(input("Entrez le port sur lequel le serveur va être : "))
|
||||
|
||||
self.clients = []
|
||||
|
||||
self.s.bind((host,port))
|
||||
self.s.listen(100)
|
||||
|
||||
print("Ip de l'host "+str(host))
|
||||
print('Marche sur le port '+str(port))
|
||||
|
||||
self.username_lookup = {}
|
||||
|
||||
while True:
|
||||
c, addr = self.s.accept()
|
||||
|
||||
username = c.recv(1024).decode()
|
||||
|
||||
print('Nouvelle connection : Pseudo '+str(username))
|
||||
self.broadcast('Nouvelle personne à rejoind : Pseudo '+username)
|
||||
|
||||
self.username_lookup[c] = username
|
||||
|
||||
self.clients.append(c)
|
||||
|
||||
threading.Thread(target=self.handle_client,args=(c,addr,)).start()
|
||||
|
||||
def broadcast(self,msg):
|
||||
for connection in self.clients:
|
||||
connection.send(msg.encode())
|
||||
|
||||
def handle_client(self,c,addr):
|
||||
while True:
|
||||
try:
|
||||
msg = c.recv(1024)
|
||||
except:
|
||||
c.shutdown(socket.SHUT_RDWR)
|
||||
self.clients.remove(c)
|
||||
|
||||
print(str(self.username_lookup[c])+' est parti')
|
||||
self.broadcast(str(self.username_lookup[c])+' a quite')
|
||||
|
||||
break
|
||||
|
||||
if msg.decode() != '':
|
||||
print(str(msg.decode()))
|
||||
for connection in self.clients:
|
||||
if connection != c:
|
||||
connection.send(msg)
|
||||
|
||||
|
||||
server = Server()
|
Loading…
Reference in new issue