-
Notifications
You must be signed in to change notification settings - Fork 0
/
neitris_cli.py
86 lines (62 loc) · 2.18 KB
/
neitris_cli.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#
# Neitris - A multiplayer Tetris clone
# Copyright (C) 2006 Alexandros Kostopoulos (akostopou@gmail.com)
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
import time, sys
import struct
from socket import socket, AF_INET, SOCK_STREAM
#import neitris
# These are server side calls
#sockobj.bind((HOSTNAME, PORT))
#sockobj.listen(5)
message = ["Ping!"]
connected = 0
#readsock = None
#------------ Threaded Stuff ----------------#
DONE = 0
# I'm using PORTS 7777 and 7778
def ChatRead(PORT, rqueue, readsock):
# global readsock
buf = ''
while not DONE:
data = readsock.recv(1024)
# print "read from socket: ", data
buf = buf + data
while 1:
if len(buf) >= 2:
(lenbuf,) = struct.unpack("!H", buf[:2])
else:
break
if len(buf) >= lenbuf + 2:
#print "playername: ", buf[0]
# if buf[2] != playername:
rqueue.put_nowait(buf[:lenbuf+2])
buf = buf[(lenbuf+2):]
else:
break
readsock.close()
return
def ChatWrite(PORT, wqueue, readsock):
# global readsock
while not DONE:
while not wqueue.empty():
data = wqueue.get_nowait()
# print "written ", data
readsock.send(data)
time.sleep(0.2)
#writesock.close()
return