Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • lahtp-common/multithreaded-math-server
  • krithikramraja/multithreaded-math-server
  • SiddharthSanthosh/multithreaded-math-server
  • tharunvt/multithreaded-math-server
  • selva1011/multithreaded-math-server
  • Deepakkumar/multithreaded-math-server
  • ganesha005/multithreaded-math-server
  • revanth/multithreaded-math-server
  • Sriraman/multithreaded-math-server
  • Adhiyaman/multithreaded-math-server
  • tamil0323/multithreaded-math-server
  • sr_subin/multithreaded-math-server
  • Nirmalkumar/multithreaded-math-server
  • arunmozhi5284/multithreaded-math-server
  • ram_rogers/multithreaded-math-server
  • monish-palanikumar/multithreaded-math-server
  • Gokul_Krish_Nan/multithreaded-math-server
  • Sabarish/multithreaded-math-server
  • Karthik/multithreaded-math-server
  • Arivazhagan_S/multithreaded-math-server
  • Thamizhpathi/multithreaded-math-server
  • Pranesh/multithreaded-math-server
  • dhugeshwaran/multithreaded-math-server
  • Sherif7/multithreaded-math-server
  • shaik_sultan31/multithreaded-math-server
  • Thiru/multithreaded-math-server
  • rii/multithreaded-math-server
  • kalish/multithreaded-math-server
28 results
Show changes
Commits on Source (1)
class MathServerCommunicationThread(Thread):
def __init__(self, conn, addr):
Thread.__init__(self)
self.conn = conn
self.addr = addr
def run(self):
print("{} connected with back port {}".format(self.addr[0], self.addr[1]))
self.conn.sendall("Simple Math Server developed by LAHTP \n\nGive any math expressions, and I will answer you :) \n\n$ ".encode())
p = Popen(['bc'], stdout=PIPE, stdin=PIPE, stderr=STDOUT)
output = ProcessOutputThread(p, self.conn)
output.start()
while not p.stdout.closed or not self.conn._closed:
try:
data = self.conn.recv(1024)
if not data:
break
else:
try:
data = data.decode()
query = data.strip()
if query == 'quit' or query == 'exit':
p.communicate(query.encode(), timeout=1)
if p.poll() is not None:
break
query = query + '\n'
p.stdin.write(query.encode())
p.stdin.flush()
except:
pass
except:
pass
self.conn.close()
import socket import socket
from subprocess import Popen, STDOUT, PIPE from subprocess import Popen, STDOUT, PIPE
from threading import Thread from threading import Thread
from comm_thread import MathServerCommunicationThread
from comm_thread import ProcessOutputThread
HOST = ''
PORT = 4444
def start_new_math_thread(conn, addr): def start_new_math_thread(conn, addr):
t = MathServerCommunicationThread(conn, addr) t = MathServerCommunicationThread(conn, addr)
t.start() t.start()
class ProcessOutputThread(Thread): #OOPS
def __init__(self, proc, conn):
Thread.__init__(self)
self.proc = proc
self.conn = conn
def run(self):
while not self.proc.stdout.closed and not self.conn._closed:
try:
self.conn.sendall(self.proc.stdout.readline())
except:
pass
class MathServerCommunicationThread(Thread):
def __init__(self, conn, addr):
Thread.__init__(self)
self.conn = conn
self.addr = addr
def run(self):
print("{} connected with back port {}".format(self.addr[0], self.addr[1]))
self.conn.sendall("Simple Math Server developed by LAHTP \n\nGive any math expressions, and I will answer you :) \n\n$ ".encode())
## APPLICATION LAYER 7
p = Popen(['bc'], stdout=PIPE, stdin=PIPE, stderr=STDOUT)
output = ProcessOutputThread(p, self.conn)
output.start()
while not p.stdout.closed or not self.conn._closed:
try: ## PRESENTATION LAYER 6
data = self.conn.recv(1024)
if not data:
break
else:
try:
data = data.decode()
query = data.strip()
if query == 'quit' or query == 'exit':
p.communicate(query.encode(), timeout=1)
if p.poll() is not None:
break
query = query + '\n'
p.stdin.write(query.encode())
p.stdin.flush()
except:
pass
except:
pass
self.conn.close()
HOST = ''
PORT = 3074
## SESSION LAYER 5
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.bind((HOST, PORT)) s.bind((HOST, PORT))
...@@ -19,3 +68,5 @@ while True: # To accept many incoming connections. ...@@ -19,3 +68,5 @@ while True: # To accept many incoming connections.
conn, addr = s.accept() # Open door conn, addr = s.accept() # Open door
start_new_math_thread(conn, addr) start_new_math_thread(conn, addr)
s.close() s.close()
class ProcessOutputThread(Thread): #OOPS
def __init__(self, proc, conn):
Thread.__init__(self)
self.proc = proc
self.conn = conn
def run(self):
while not self.proc.stdout.closed and not self.conn._closed:
try:
self.conn.sendall(self.proc.stdout.readline())
except:
pass