Example #1
0
 def run(self):
     """Block and start listening for connections from clients. An
     interrupt (^C) closes the server.
     """
     self.startup_time = time.time()
     bluelet.run(bluelet.server(self.host, self.port,
                                Connection.handler(self)))
Example #2
0
 def run(self):
     """Block and start listening for connections from clients. An
     interrupt (^C) closes the server.
     """
     self.startup_time = time.time()
     bluelet.run(bluelet.server(self.host, self.port,
                                Connection.handler(self)))
Example #3
0
 def run(self):
     bluelet.run(bluelet.server('', cw.PORT, self.communicate))
Example #4
0
        if i!=conn:#Se i for diferente da minha conta
            yield i.sendall(mensagem.encode())#Envia para todos na lista contas menos para mim
    while True:
        data = yield conn.recv(1024)#pega dado da conexão
        if not data:
            break
        for n in nomes:#Pecorre a lista nomes
            comp="%s:exit()"%n#Irá servir como base para comparar
            if comp==data.decode('utf8'):#Se a mensagem em data for igual a "nome da pessoa: exit()" 
                nomes.remove(n)#Se remove o nome de quem enviou da lista nomes
                contas.remove(conn)#Remove o conn de quem enviou da lista contas
                resposta ="%s saiu da conversa" %n#Resposta que será enviada aos clientes conectados 
                data = resposta.encode()
        for n in nomes:
            commandWhoIsOn = "%s:Who is on?" %n
            if commandWhoIsOn==data.decode('utf8'):
                data=b''
                for userOn in nomes:
                    who ="%s está online" %userOn
                    yield conn.sendall(who.encode())
                    
        for i in contas:#Vai pegar todas as conexões que estão na lista contas
            if i!=conn:#Se "i" for diferente da conexão que está enviando a mensagem
                yield i.sendall(data)#envia a mensagem para as outra conexões
		
contas=[]
nomes=[]
if __name__=="__main__":
    print("Servidor Rodando...")
    bluelet.run(bluelet.server('', 4915, echoer))
Example #5
0
if __name__ == '__main__':
    
    
    host = socket.gethostname()  # '127.0.0.1' can also be used
    serverfile = open('server.txt')
    lines = serverfile.readlines()
    #taskfile = open('test.txt')
    #tlines = taskfile.readlines()

    server_s = []
    task_types = []
    
    data1 = []
    
    bluelet.run(bluelet.server('', 9001, echoer))
    
    for line in lines:
        line = line.split(' ')
        for i in range (0,3):
            line[i] = int(line[i])
        if len(line) == 4:
            name = line[3]
        elif len(line) == 3:
            name = 'Server'
        else:
            raise Exception('Invalid Server.txt file structure')
        if int(line[0])>0:
            server_s.append(Server(capacity=line[0], occ=line[1], port=line[2], name=name))
    
    temp2 = []
Example #6
0
    # Get the HTTP request.
    request = []
    while True:
        line = (yield conn.readline(b'\r\n')).strip()
        if not line:
            # End of headers.
            break
        request.append(line)

    # Make sure a request was sent.
    if not request:
        return

    # Parse and log the request and get the response values.
    method, path, headers = parse_request(request)
    print('%s %s' % (method, path))
    status, headers, content = respond(method, path, headers)

    # Send response.
    yield conn.sendall(("HTTP/1.1 %s\r\n" % status).encode('utf8'))
    for key, value in headers.items():
        yield conn.sendall(("%s: %s\r\n" % (key, value)).encode('utf8'))
    yield conn.sendall(b"\r\n")
    yield conn.sendall(content)

if __name__ == '__main__':
    if len(sys.argv) > 1:
        ROOT = os.path.expanduser(sys.argv[1])
    print('http://127.0.0.1:8000/')
    bluelet.run(bluelet.server('', 8000, webrequest))
Example #7
0
import bluelet


def echoer(conn):
    while True:
        data = yield conn.recv(1024)
        if not data:
            break
        print "CLIENT:", data
        yield conn.sendall(data)


bluelet.run(bluelet.server('127.0.0.1', 4915, echoer))
Example #8
0
import sys
sys.path.insert(0, '..')
import bluelet


def echoer(conn):
    while True:
        data = yield conn.recv(1024)
        if not data:
            break
        yield conn.sendall(data)


if __name__ == '__main__':
    bluelet.run(bluelet.server('', 4915, echoer))
Example #9
0
    request = []
    while True:
        line = (yield conn.readline(b'\r\n')).strip()
        if not line:
            # End of headers.
            break
        request.append(line)

    # Make sure a request was sent.
    if not request:
        return

    # Parse and log the request and get the response values.
    method, path, headers = parse_request(request)
    print('%s %s' % (method, path))
    status, headers, content = respond(method, path, headers)

    # Send response.
    yield conn.sendall(("HTTP/1.1 %s\r\n" % status).encode('utf8'))
    for key, value in headers.items():
        yield conn.sendall(("%s: %s\r\n" % (key, value)).encode('utf8'))
    yield conn.sendall(b"\r\n")
    yield conn.sendall(content)


if __name__ == '__main__':
    if len(sys.argv) > 1:
        ROOT = os.path.expanduser(sys.argv[1])
    print('http://127.0.0.1:8000/')
    bluelet.run(bluelet.server('', 8000, webrequest))
Example #10
0
########NEW FILE########
__FILENAME__ = echo_simple
import sys
sys.path.insert(0, '..')
import bluelet

def echoer(conn):
    while True:
        data = yield conn.recv(1024)
        if not data:
            break
        yield conn.sendall(data)

if __name__ == '__main__':
    bluelet.run(bluelet.server('', 4915, echoer))

########NEW FILE########
__FILENAME__ = httpd
"""A simple Web server built with Bluelet to support concurrent requests
in a single OS thread.
"""
from __future__ import print_function
import sys
import os
import mimetypes
sys.path.insert(0, '..')
import bluelet

ROOT = '.'
INDEX_FILENAME = 'index.html'
if __name__ == '__main__':
    
    
    host = socket.gethostname()  # '127.0.0.1' can also be used
    serverfile = open('server.txt')
    lines = serverfile.readlines()
    #taskfile = open('test.txt')
    #tlines = taskfile.readlines()

    server_s = []
    task_types = []
    
    data1 = []
    
    bluelet.run(bluelet.server('', 9001, echoer))
    
    for line in lines:
        line = line.split(' ')
        for i in range (0,3):
            line[i] = int(line[i])
        if len(line) == 4:
            name = line[3]
        elif len(line) == 3:
            name = 'Server'
        else:
            raise Exception('Invalid Server.txt file structure')
        if int(line[0])>0:
            server_s.append(Server(capacity=line[0], occ=line[1], port=line[2], name=name))
    
    temp2 = []