Oops. It is printing the sent data though, and the server seems to be
receiving it, but the client isn't waiting at the server.recv() function.
I'm getting a connection abortion error, though I don't know why it would
be trying to do that.
C:\Users\Lemonilla\Documents\Programming\$ GitHub\Space\Server>pyglettest.py
Enter IP of the server you with to connect to.
>localhost
Attempting socket 5000
Waiting for server to respond. . .
Launching Game. . .
{'Lemonilla':[]}
{'Lemonilla':[]}
Traceback (most recent call last):
File "C:\Users\Lemonilla\Documents\Programming\$
GitHub\Space\Server\pygletTes
t.py", line 173, in <module>
app.run()
File "C:\Python27\lib\site-packages\pyglet\app\__init__.py", line 143, in
run
event_loop.run()
File "C:\Python27\lib\site-packages\pyglet\app\base.py", line 136, in run
self._run_estimated()
File "C:\Python27\lib\site-packages\pyglet\app\base.py", line 165, in
_run_est
imated
timeout = self.idle()
File "C:\Python27\lib\site-packages\pyglet\app\base.py", line 274, in idle
redraw_all = self.clock.call_scheduled_functions(dt)
File "C:\Python27\lib\site-packages\pyglet\clock.py", line 309, in
call_schedu
led_functions
item.func(ts - item.last_ts, *item.args, **item.kwargs)
File "C:\Users\Lemonilla\Documents\Programming\$
GitHub\Space\Server\pygletTes
t.py", line 166, in update
check_crash()
File "C:\Users\Lemonilla\Documents\Programming\$
GitHub\Space\Server\pygletTes
t.py", line 100, in check_crash
collidables = server.recv(1000)
socket.error: [Errno 10053] An established connection was aborted by the
softwar
e in your host machine
Updated client code:
from pyglet.window import Window,key
from pyglet import app
from pyglet.text import Label
from pyglet.clock import schedule_interval
import random, socket
Keys = [False,False,False,False,False] # [W,A,S,D,FIRE]
last = Keys
bullets = []
bullet_speed = 3
bullet_life = 5
point = {'x':0,'y':0}
size = 100 # query server for size
map_size=10
username = "Lemonilla"
# Game Setup
print "Enter IP of the server you with to connect to."
server_IP = raw_input(">")
port = None
while port == None:
for x in xrange(0,50):
try:
print "\r \r
Attempting socket %d" % (5000+x),
server = socket.socket(socket.AF_INET, socket.
SOCK_STREAM)
server.connect((server_IP,5000+x))
port = 5000+x
break
except:
pass
server.sendall(username)
print "\n Waiting for server to respond. . ."
size = server.recv(10)
print " Launching Game. . ."
win = Window()
ScreenMap = Label("")
def move():
global Keys,point,last
if Keys[0] == True: # W
point['y']+=1
if Keys[1] == True: # A
point['x']-=1
if Keys[2] == True: # S
point['y']-=1
if Keys[3] == True: # D
point['x']+=1
if Keys[4] == True: # SPACE
Fire()
last = Keys
def Fire():
global last
# bullet = [x, y, distance to travel, direction]
# (W, A, S, D, FIRE)
bullets.append((point['x'], point['y'], bullet_life, list(last)))
def decay():
global bullets
index=0
for b in bullets:
bullet_x=b[0]
bullet_y=b[1]
if b[3][0] == True:
bullet_y=b[1]+bullet_speed
if b[3][2] == True:
bullet_y=b[1]-bullet_speed
if b[3][1] == True:
bullet_x=b[0]-bullet_speed
if b[3][3] == True:
bullet_x=b[0]+bullet_speed
if b[2]-1 > 0:
bullets[index] = (bullet_x, bullet_y, b[2]-1, b[3])
else:
bullets[index] = None
index+=1
while bullets.count(None) > 0:
bullets.remove(None)
def check_crash():
collidables = None
send = "{\'"+str(username)+"\':"+str(bullets)+"}"
server.sendall(send)
print send
# Query Server for Colidables list
while collidables == None:
collidables = server.recv(1000)
print collidables
def buildScreen():
global ScreenMap, win, point, map_size
screen = ""
for y in xrange(point['y']+map_size+1,point['y']-map_size,-1):
for x in xrange(point['x']-map_size-1,point['x']+map_size):
if not(x == point['x'] and y == point['y']):
printed = False
for b in bullets:
if x == b[0] and y == b[1]:
if not(printed):
screen+=" +"
printed = True
if not(printed):
screen+=" . "
else:
screen+=" @"
screen+="\n"
ScreenMap = Label(str(screen), x=0, y=win.height, width=win.width,
multiline=True)
@win.event
def on_key_press(symbol, modifiers):
global Keys,ScreenMap
if symbol == key.A:
Keys[1] = True
if symbol == key.S:
Keys[2] = True
if symbol == key.W:
Keys[0] = True
if symbol == key.D:
Keys[3] = True
if symbol == key.SPACE:
Keys[4] = True
win.clear()
ScreenMap.draw()
@win.event
def on_key_release(symbol, modifiers):
global Keys,ScreenMap
if symbol == key.A:
Keys[1] = False
if symbol == key.S:
Keys[2] = False
if symbol == key.W:
Keys[0] = False
if symbol == key.D:
Keys[3] = False
if symbol == key.SPACE:
Keys[4] = False
win.clear()
ScreenMap.draw()
def update(dt):
global Keys,ScreenMap,point
buildScreen()
move()
decay()
check_crash()
win.clear()
ScreenMap.draw()
point_label = Label("%d,%d" % (point['x'],point['y']))
point_label.draw()
schedule_interval(update, 0.1)
app.run()
On Tuesday, May 26, 2015 at 3:55:53 AM UTC-4, [email protected] wrote:
>
> You know, taking a closer look at your client code, specifically in your
> check_crash() Function:
>
> def check_crash():
> *---> **return*
> send = "{\'"+str(username)+"\':"+str(bullets)+"}"
> server.sendall(send)
> print send
> # Query Server for Colidables list
> collidables = server.recv(1000000)
> print collidables
>
> Return will immediately end a function and return a result to whatever
> called it (IE: return x), which means anything after it will be completely
> ignored.
> Typically you want to put that at the end of a function or at any point
> you want to return a result and stop processing, so that might be your
> problem there
> since that seems to handle your network functions.
>
>
>
--
You received this message because you are subscribed to the Google Groups
"pyglet-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/pyglet-users.
For more options, visit https://groups.google.com/d/optout.