Aug-10-2020, 05:57 PM
HI fellow nerds,
I was playing with sockets when this 10057 error occured.
The description by microsoft is:
A request to send or receive data was disallowed because the socket is not connected and (when sending on a datagram socket using sendto) no address was supplied.
My code is for an online game, just ignore the pygame stuff.
server:
how do I fix that?
Thanks
I was playing with sockets when this 10057 error occured.
The description by microsoft is:
A request to send or receive data was disallowed because the socket is not connected and (when sending on a datagram socket using sendto) no address was supplied.
My code is for an online game, just ignore the pygame stuff.
server:
import socket import sys import pickle as pk import pygame as g Gbois = [] Nbois = [] def servi(): while True: try: s.listen(5) client, adress = s.accept() client.send('Welcome in da bros! \n'.encode()) gettin = bytearray() while True: add = s.recv(2048) if add.decode() == '': break else: gettin.extend(add) pl = pk.loads(gettin) if pl.name in Nbois: Gbois[Nbois.index(pl.name)] = pl else: Nbois.append(pl.name) Gbois.append(pl) risp = pk.dumps(Gbois) client.send(risp) except socket.error as fac: print(f'errore nella konnesione kol klient :/ \n #@# {fac} \nNuovo tentativo in korso...') s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) try: s.bind((socket.gethostname(), 1001)) print("wooa! Stai fachin' hostin'") except socket.error as error: print(f"forx c'è un errore: \n {error}") input("enter per ushire") sys.exit() servi()client:
import pygame as g import socket import sys import pickle as pk s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) clock = g.time.Clock() class boi: def __init__(self, x, y, name): self.o = g.Rect(x, y, 30, 30) self.name = name bois = [] xspid, yspid = (0, 0) def submit(me): global s global bois bois = [] gg = pk.dumps(me) s.send(gg) gettin = bytearray() while True: add = s.recv(2048) if add.decode() == '': break else: gettin.extend(add) bois = pk.loads(gettin) s.close() s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect((Ip, 1001)) trash = s.recv(4194304) Ip = input("\ninserishy ip: ") print("\nstartin' session...\n") try: s.connect((Ip, 1001)) print(f"konnesso a {Ip}! <3 ") except socket.error as error: print(f"Forx! Qualcosa è andato storto :/ \n {error}") input("enter per ushire") sys.exit() msg = s.recv(2048) print(msg.decode()) player = boi(0, 0, input('Iuserneim: ')) size = (800, 600) sw, sh = size screen = g.display.set_mode(size) g.display.set_caption('Online Mess! - Umanochiocciola') run = True while run: for ev in g.event.get(): if ev.type == g.QUIT: run = False if ev.type == g.KEYUP: if ev.key == g.K_w: yspid += 5 if ev.key == g.K_s: yspid -= 5 if ev.key == g.K_a: xspid += 5 if ev.key == g.K_d: xspid -= 5 if ev.type == g.KEYDOWN: if ev.key == g.K_w: yspid -= 5 if ev.key == g.K_s: yspid += 5 if ev.key == g.K_a: xspid -= 5 if ev.key == g.K_d: xspid += 5 player.o.x += xspid player.o.y += yspid if player.o.x >= sw - 30: player.o.x = sw - 30 if player.o.x <= 0: player.o.x = 0 if player.o.y >= sh - 30: player.o.y = sh - 30 if player.o.y <= 0: player.o.y = 0 submit(player) screen.fill((50, 50, 50)) for bo in bois: g.draw.rect(screen, (50, 50, 250), bo.o ) g.draw.rect(screen, (250, 50, 50), player.o) g.display.flip() clock.tick(60)
how do I fix that?
Thanks