Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
M
mensactrl
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
stratum0
mensactrl
Commits
ff774e36
Commit
ff774e36
authored
10 years ago
by
Jan Luebbe
Browse files
Options
Downloads
Patches
Plain Diff
Update python code for multi messages and test-server for blit.
parent
8170f199
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
python/client.py
+9
-3
9 additions, 3 deletions
python/client.py
python/gol-client.py
+3
-1
3 additions, 1 deletion
python/gol-client.py
python/test-client.py
+4
-20
4 additions, 20 deletions
python/test-client.py
python/test-server.py
+21
-5
21 additions, 5 deletions
python/test-server.py
with
37 additions
and
29 deletions
python/client.py
100755 → 100644
+
9
−
3
View file @
ff774e36
...
...
@@ -21,9 +21,15 @@ socket = context.socket(zmq.REQ)
socket
.
connect
(
SERVER
)
def
set_pixel
(
x
,
y
,
v
):
tx
=
bytearray
(
9
)
struct
.
pack_into
(
'
iiB
'
,
tx
,
0
,
x
,
y
,
v
)
socket
.
send
(
tx
)
tx
=
struct
.
pack
(
'
<BiiB
'
,
0
,
x
,
y
,
v
)
socket
.
send_multipart
([
tx
,
b
''
])
rx
=
socket
.
recv
()
#print("Received reply %s [%r]" % ((x, y, v), rx))
def
set_pixels
(
pixels
):
msg
=
[]
for
x
,
y
,
v
in
pixels
:
msg
.
append
(
struct
.
pack
(
'
<BiiB
'
,
0
,
x
,
y
,
v
))
socket
.
send_multipart
(
msg
+
[
b
''
])
rx
=
socket
.
recv
()
This diff is collapsed.
Click to expand it.
python/gol-client.py
+
3
−
1
View file @
ff774e36
...
...
@@ -7,10 +7,12 @@ SIZE = 1
import
time
def
rect
(
x
,
y
,
w
,
h
,
r
,
g
,
b
):
pixels
=
[]
for
i
in
xrange
(
x
,
x
+
w
):
for
j
in
xrange
(
y
,
y
+
h
):
#pixel(i,j,r,g,b)
client
.
set_pixel
(
i
,
j
,
r
)
pixels
.
append
((
i
,
j
,
r
))
client
.
set_pixels
(
pixels
)
def
draw
(
x
,
y
,
v
):
rect
(
x
*
SIZE
,
y
*
SIZE
,
SIZE
,
SIZE
,
255
*
v
,
255
*
v
,
255
*
v
)
...
...
This diff is collapsed.
Click to expand it.
python/test-client.py
+
4
−
20
View file @
ff774e36
#!/usr/bin/python
import
sys
import
sys
,
client
SERVER
=
"
tcp://localhost:5571
"
XOFF
=
0
YOFF
=
0
TEXT
=
"
Hello World!
"
if
__name__
==
"
__main__
"
:
if
len
(
sys
.
argv
)
>=
2
:
SERVER
=
sys
.
argv
[
1
]
if
len
(
sys
.
argv
)
>=
4
:
XOFF
=
int
(
sys
.
argv
[
2
])
YOFF
=
int
(
sys
.
argv
[
3
])
if
len
(
sys
.
argv
)
>=
5
:
TEXT
=
sys
.
argv
[
4
]
import
struct
import
zmq
# Prepare our context and sockets
context
=
zmq
.
Context
()
socket
=
context
.
socket
(
zmq
.
REQ
)
socket
.
connect
(
SERVER
)
def
set_pixel
(
x
,
y
,
v
):
tx
=
bytearray
(
9
)
struct
.
pack_into
(
'
iiB
'
,
tx
,
0
,
x
,
y
,
v
)
socket
.
send
(
tx
)
rx
=
socket
.
recv
()
#print("Received reply %s [%r]" % ((x, y, v), rx))
import
pygame
pygame
.
init
()
font
=
pygame
.
font
.
Font
(
"
/usr/share/fonts/X11/misc/5x7.pcf.gz
"
,
7
)
text
=
font
.
render
(
TEXT
,
True
,
(
255
,
255
,
255
),
(
0
,
0
,
0
))
pxarray
=
pygame
.
PixelArray
(
text
)
pixels
=
[]
for
x
in
range
(
text
.
get_width
()):
for
y
in
range
(
text
.
get_height
()):
set_
pixel
(
XOFF
+
x
,
YOFF
+
y
,
pxarray
[
x
][
y
])
pixel
s
.
append
(
(
XOFF
+
x
,
YOFF
+
y
,
pxarray
[
x
][
y
])
)
del
pxarray
client
.
set_pixels
(
pixels
)
This diff is collapsed.
Click to expand it.
python/test-server.py
+
21
−
5
View file @
ff774e36
...
...
@@ -42,8 +42,24 @@ while True:
pygame
.
display
.
update
()
continue
message
=
socket
.
recv
()
x
,
y
,
v
=
struct
.
unpack_from
(
'
iiB
'
,
message
)
# print("Received request: %r, %r, %r" % (x, y, v))
set_pixel
(
x
,
y
,
v
)
socket
.
send
(
b
""
)
messages
=
socket
.
recv_multipart
()
#print("New multimessage")
for
message
in
messages
:
if
not
message
:
break
cmd
,
=
struct
.
unpack_from
(
'
<B
'
,
message
)
#print repr(message)
if
cmd
==
0
:
# set pixel
cmd
,
x
,
y
,
v
=
struct
.
unpack_from
(
'
<BiiB
'
,
message
)
#print("Received set pixel: %r, %r, %r, %r" % (cmd, x, y, v))
set_pixel
(
x
,
y
,
v
)
elif
cmd
==
1
:
# blit
cmd
,
x
,
y
,
w
,
h
=
struct
.
unpack_from
(
'
<Biiii
'
,
message
)
#print("Received blit: %r, %r, %r, %r, %r" % (cmd, x, y, w, h))
for
r
in
range
(
h
):
for
c
in
range
(
w
):
set_pixel
(
x
+
c
,
y
+
r
,
ord
(
message
[
17
+
r
*
w
+
c
]))
else
:
cmd
,
=
struct
.
unpack_from
(
'
<B
'
,
message
)
print
(
"
Received unknown: %r
"
%
(
cmd
,))
socket
.
send
(
b
''
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment