aboutsummaryrefslogtreecommitdiff
path: root/backend/microservice/PythonServer/project/api/socket2/server.py
diff options
context:
space:
mode:
authorDanijel Andjelkovic <adanijel99@gmail.com>2022-03-16 23:12:04 +0100
committerDanijel Andjelkovic <adanijel99@gmail.com>2022-03-16 23:12:04 +0100
commitfa3f1c9a333a51097c360b60bcdb2d63f6c6de2c (patch)
tree38e10d34707e80d72f4c9704c93b4e649f4e61f9 /backend/microservice/PythonServer/project/api/socket2/server.py
parent7aa1719639bb0a90114cca2c9a95e58bef22eef0 (diff)
parent5ed7414d83bacf3648a6ea194f072652bfa03b25 (diff)
Merge branch 'dev' of http://gitlab.pmf.kg.ac.rs/igrannonica/neuronstellar into dev
# Conflicts: # frontend/src/app/_data/Model.ts # frontend/src/app/_pages/add-model/add-model.component.ts
Diffstat (limited to 'backend/microservice/PythonServer/project/api/socket2/server.py')
-rw-r--r--backend/microservice/PythonServer/project/api/socket2/server.py39
1 files changed, 39 insertions, 0 deletions
diff --git a/backend/microservice/PythonServer/project/api/socket2/server.py b/backend/microservice/PythonServer/project/api/socket2/server.py
new file mode 100644
index 00000000..c65dae78
--- /dev/null
+++ b/backend/microservice/PythonServer/project/api/socket2/server.py
@@ -0,0 +1,39 @@
+# first of all import the socket library
+import socket
+
+# next create a socket object
+s = socket.socket()
+print ("Socket successfully created")
+
+# reserve a port on your computer in our
+# case it is 12345 but it can be anything
+port = 12345
+
+# Next bind to the port
+# we have not typed any ip in the ip field
+# instead we have inputted an empty string
+# this makes the server listen to requests
+# coming from other computers on the network
+s.bind(('', port))
+print ("socket binded to %s" %(port))
+
+# put the socket into listening mode
+s.listen(5)
+print ("socket is listening")
+
+# a forever loop until we interrupt it or
+# an error occurs
+while True:
+
+# Establish connection with client.
+ c, addr = s.accept()
+ print ('Got connection from', addr )
+
+ # send a thank you message to the client. encoding to send byte type.
+ c.send('Thank you for connecting'.encode())
+
+ # Close the connection with the client
+ c.close()
+
+ # Breaking once connection closed
+ break \ No newline at end of file