Code Monkey home page Code Monkey logo

Comments (4)

Top-Ranger avatar Top-Ranger commented on August 21, 2024

Der Client kann sich dann wieder mit dem Server verbinden, sobald das Spiel beendet ist, an dem der Client teilnimmt. Dabei müsst ihr beachten, dass das Spiel auch weiterlaufen kann, auch wenn euer Client keine Verbindung mehr zum Server hat. In dem Fall müsst ihr warten, bis das Spiel vorbei ist (dies ist leider nicht ersichtlich, wenn ihr nicht mehr mit dem Spiel verbunden seid).

Bitte beachtet, dass es etwas dauern kann, bis der erste Spielstatus übertragen wird. Solange auf den Start des Spiels gewartet wird werden keine Daten übertragen.

from informaticup2021.

DiddiZ avatar DiddiZ commented on August 21, 2024

Genau so dachte ich mir das. Allerdings sollte das nicht mehrere Stunden dauern.

z.B. haben wir gestern gegen 22:30 aus Versehen von zwei Client aus connected und dafür den Error 429 erhalten. Danach konnten wir über Stunden nicht mehr erfolgreich verbinden. Um halb 1 ging es nocht nicht, erst heute Morgen klappt es wieder.

Ausschnitt aus unserem Log:

2020-11-01 22:18:52 DEBUG: client < HTTP/1.1 429 Too Many Requests
2020-11-01 22:20:52 DEBUG: client < HTTP/1.1 429 Too Many Requests
2020-11-01 22:26:54 DEBUG: client < HTTP/1.1 429 Too Many Requests
2020-11-01 22:28:54 DEBUG: client < HTTP/1.1 429 Too Many Requests
2020-11-01 22:31:55 DEBUG: client < HTTP/1.1 429 Too Many Requests
2020-11-01 22:34:56 DEBUG: client < HTTP/1.1 429 Too Many Requests
2020-11-01 22:37:57 DEBUG: client < HTTP/1.1 429 Too Many Requests
2020-11-01 22:40:57 DEBUG: client < HTTP/1.1 429 Too Many Requests
2020-11-01 22:42:58 DEBUG: client < HTTP/1.1 429 Too Many Requests
2020-11-01 22:47:59 DEBUG: client < HTTP/1.1 429 Too Many Requests
2020-11-01 22:53:01 DEBUG: client < HTTP/1.1 429 Too Many Requests
2020-11-01 22:58:02 DEBUG: client < HTTP/1.1 429 Too Many Requests
2020-11-01 23:03:03 DEBUG: client < HTTP/1.1 429 Too Many Requests
2020-11-01 23:09:05 DEBUG: client < HTTP/1.1 429 Too Many Requests
2020-11-02 00:06:36 DEBUG: client < HTTP/1.1 429 Too Many Requests
2020-11-01 23:32:06 DEBUG: client < HTTP/1.1 429 Too Many Requests
2020-11-01 23:33:06 DEBUG: client < HTTP/1.1 429 Too Many Requests

Ich habe den Eindruck, das nicht erfolgreiche Verbindungsversuche dafür sorgen, dass der nächste Verbindungsversuch ebenfalls nicht erfolgreich ist. Es funktioniert erst wieder, wenn man die Verbindungsschleife beendet und einige Stunden wartet.

from informaticup2021.

Top-Ranger avatar Top-Ranger commented on August 21, 2024

Ein erfolgloser Versuch verhindert keine weiteren Versuche. Wenn sich zwei verschiedene Clienten verbinden, dann bleibt der erste im Spiel / in der Lobby (und kann das Spiel zu Ende spielen) und der zweite bekommt die 429-Meldung. So weit ich das nachvollziehen kann sind auch für alle Teilnehmer, die sich in dem Zeitraum mit der API verbunden haben, Spiele gestartet worden.

from informaticup2021.

DiddiZ avatar DiddiZ commented on August 21, 2024

MWE:

#!/usr/bin/env python3

import asyncio
import json
import os
import random
import websockets


async def connect_and_quit():
    url = os.environ["URL"]
    key = os.environ["KEY"]

    async with websockets.connect(f"{url}?key={key}"):
        print("Connected", flush=True)
    print("Disconnected", flush=True)


async def play():
    url = os.environ["URL"]
    key = os.environ["KEY"]

    print("Connecting", flush=True)
    try:
        async with websockets.connect(f"{url}?key={key}") as websocket:
            print("Waiting for initial state...", flush=True)
            while True:
                state_json = await websocket.recv()
                state = json.loads(state_json)
                print("<", state)
                own_player = state["players"][str(state["you"])]
                if not state["running"] or not own_player["active"]:
                    break
                valid_actions = ["turn_left", "turn_right", "change_nothing"]
                if own_player["speed"] < 10:
                    valid_actions += ["speed_up"]
                if own_player["speed"] > 1:
                    valid_actions += ["slow_down"]
                action = random.choice(valid_actions)
                print(">", action)
                action_json = json.dumps({"action": action})
                await websocket.send(action_json)
    except websockets.exceptions.InvalidStatusCode as e:
        if e.status_code == 429:  # Server rejects us
            print("Server rejected connection", flush=True)

            # Sleep and try again
            await asyncio.sleep(60)
            await play()
        else:  # Other status code, not handled here
            raise


asyncio.get_event_loop().run_until_complete(connect_and_quit())
asyncio.get_event_loop().run_until_complete(play())

Und tatsächlich, das funktioniert wie erwartet. Dann liegt das Problem wohl auf unserer Seite. Auch wenn es sehr merkwürdig ist, dass es auch nach einem Restart des Docker-Containers nicht geklappt hat. Aber dann kann das hier zu.

from informaticup2021.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.