예제 #1
0
    def open(self):
        #print("self_info: " + self)
        if self not in cl:
            cl.append(self)
            print("open")

        self.c = ClientClass('0')
        #クライアント用のsocketクライアントをここで作る
        self.cl_th1 = threading.Thread(name="cl_th1",
                                       target=self.cl_threadTest)
        self.cl_th1.setDaemon(True)  #これを指定しない場合"ctrl+C"でスレッドが終了しないので注意
        self.cl_th1.start()
예제 #2
0
class WebSocketHandler(tornado.websocket.WebSocketHandler):
    def check_origin(self, origin):
        return True

    def open(self):
        #print("self_info: " + self)
        if self not in cl:
            cl.append(self)
            print("open")

        self.c = ClientClass('0')
        #クライアント用のsocketクライアントをここで作る
        self.cl_th1 = threading.Thread(name="cl_th1",
                                       target=self.cl_threadTest)
        self.cl_th1.setDaemon(True)  #これを指定しない場合"ctrl+C"でスレッドが終了しないので注意
        self.cl_th1.start()

    def on_message(self, message):
        print(message)
        #アプリのクライアントから送られてきたJSONメッセージをsocketサーバにおくる
        self.c.client.sendall(message.encode('utf-8'))

    def on_close(self):
        if self in cl:
            cl.remove(self)
            print("close")

    #受け取り口
    def cl_threadTest(self):
        print('受け取り口')
        message = self.c.UI_handler()
        message = message.lstrip('0:')
        print('return: {}'.format(message))
        self.write_message(message)  #これでメッセージを送り返す
예제 #3
0
 def AddInfoToDB(self, user=User.Client()):
     self.ConnectionToDB()
     cursor = self.conn.cursor()
     user_info = (user.user_id, user.login, user.password, user.sid,
                  user.nick_name)
     sql = """INSERT INTO "User" (user_id , login_user , password_user , sid_user , nickname_user) VALUES(%s,%s,%s,%s,%s)"""
     cursor.execute(sql, user_info)
     self.conn.commit()
     self.CloseConnectionDB(cursor)
예제 #4
0
    def open(self):
        self.count = 1
        print("Connection established!! at screen")

        self.c = ClientClass('1')

        #以下スレッド作成とスタート
        self.th1 = threading.Thread(name="th1", target=self.threadTest)
        #self.th1 = threading.Thread(name="th1", target=self.threadTest, args=(,))
        # 引数一つの時注意!
        self.th1.setDaemon(True)  # これを指定しない場合"ctrl+C"でスレッドが終了しないので注意
        self.th1.start()
def main_openConnection():
    server_address = 'localhost'
    server_port = 17510

    # AF_INET - IPv4 protokol, SOCK_STREAM - TCP protokol
    server_socket = socket(AF_INET, SOCK_STREAM)

    server_socket.bind((server_address, server_port))

    # Slusa za konekcije
    server_socket.listen()
    print('>> Cekanje na konekciju . . .')

    queueList = []

    while True:
        # Prihvata konekciju klijenta
        client_socket, client_address = server_socket.accept()

        greetings(client_socket)
        client = ClientClass.Client("noName", client_socket, client_address)
        queueList.append(client)

        print(
            f'>> Igrac je pristigao! U redu cekanja za igru ima ukupno {len(queueList)} igraca.'
        )

        if (len(queueList) >= 2):
            print('>> Pokrecem igru . . . ')

            try:
                #    th = threading.Thread(target=setUpGame, args=(queueList[0], queueList[1]))
                #    th.start()
                ClientHandler(queueList[0], queueList[1])
                queueList.pop(0)
                queueList.pop(
                    0
                )  # Jer zbog prethodne linije nemamo element sa indeksom 1
            except:
                print('>> Doslo je do greske prilikom pokretanja igre!')
def main():
	
	global s
	
	print '[TankistOnline - Server]'
	print '         v1.0'
	
	#Create socket
	print '[ ] Creating socket...'
	server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
	print '[X] Socket created.'
	
	#Bind socket to localhost
	print '[ ] Binding socket...'
	
	try:
		
		HOST = "0.0.0.0"
		PORT = 1234
		
		server_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
		server_socket.bind((HOST, PORT))
		print '[X] Socket bound.'
	
	except socket.error as msg:
		
		print '[!] Bind failed.'
		print '    Error Code: ' + str(msg[0])
		print '    Message ' + str(msg[1])
		sys.exit()
		
		
	#Start listening
	
	print '[ ] Starting listener...'
	server_socket.listen(10)
	print '[X] Listener started.'
	
	#Entering main loop
	
	print '[i] Entering main loop...'
	
	global conns
	
	#Create a client object for the server socket, thatway we can loop through
	#everything (including our serversocket) using select()
	
	ssock = ClientClass.Client(server_socket, "localhost") 

	ssock.isServerSocket = True
	
	conns.append(ssock)
	
	while True:
		
		read_sockets, write_sockets, error_sockets = select.select(conns,[],[])

		for sock in read_sockets:
			
			if sock == ssock: #Incoming connection
				
				sockfd, addr = sock.connection.accept()
				
				newConn = ClientClass.Client(sockfd, addr)
				greet(newConn) #Initiate the handshake
			
			else:
				
				#Data received from existing player
				
				try:
					
					data = sock.read().splitlines()[0].split(' ')
					
					if sock.status == 0:
						
						#The first line sent from the client is a nickname in response to the handshake
						#request. So the handshake is confirmed, and the client sent his nickname.
						
						sock.nick = str(data[0])
						sock.status = 1
						
						new_player(sock.nick) #Notify each player of the new arrival
						
					else:
						
						#The player has already sent in his nickname, so this must be
						#data.
						
						process(sock, data) 
				
				except:
					
					#If there's an error with the socket, close it. The game must
					#continue.
					
					try:
						
						sock.connection.shutdown()
						sock.connection.close()
						
						notify_all(sock.nick + " has left the battle.")
						
					except:
						
						print '[i] Exception in closing socket.'
					
					finally:
					
						conns.remove(sock)
예제 #7
0
import sys

sys.path.append('./Modules')
import ClientClass

Clnt = ClientClass.Client()

Clnt.OpenSerialPort()

Clnt.BatteryStatusThread()

Clnt.DrivingThread()

Clnt.ListenIO()
예제 #8
0
import ClientClass
from time import sleep

client = ClientClass.Client_Class("Itzik")
client.Connect()
dict = client.getDicionary()
dict['1'] = "Eitan"
dict['0'] = "Itzik"
print(dict)
del dict['0']
print(dict)
client.Disconnect()
예제 #9
0
import ClientClass

client1 = ClientClass.Client()
client1.run(1258)
예제 #10
0
#!/usr/bin/env python3

import sys, os
import Handler, ClientClass


if __name__ == "__main__":
    # server = EpollServer(9190)
    # server.run()
    client = ClientClass.TcpClientShell("202.38.88.230", 9190)

예제 #11
0
import ClientClass

globVars = ClientClass.GlobalVariables()
Clnt = ClientClass.Client(globVars)

Clnt.OpenSerialPort()

Clnt.BatteryStatusThread()

Clnt.DrivingThread()

Clnt.ListenIO()
예제 #12
0
heartbeat_time = 3

last_hearbeat = time.time()

while True:

    broadcastGameUpdate(connections)

    try:
        s, addr = serverSocket.accept()
    except:
        s = False

    if s:
        clientID += 1
        connections.append([ClientClass(clientID, s, addr), True])
        s.send(('?' + str(clientID) + '#\n').encode('utf-8'))

        s.settimeout(0.2)
        s.setblocking(0)

        print('Incoming connection from {}'.format(addr))

    index = 0

    for Client, hbt in connections:

        if Client.clientSocket == None or Client.clientSocket.fileno() == -1:
            continue

        try: