Code Monkey home page Code Monkey logo

Comments (7)

Amerikranian avatar Amerikranian commented on August 11, 2024

Sorry, here's a better version

server code

import enet
host = enet.Host(enet.Address(b"localhost", 54301), 10, 0, 0, 0)
while 1:
    # Wait 1 second for an event
    event = host.service(0)
    if event.type == enet.EVENT_TYPE_CONNECT:
        print("%s: CONNECT" % event.peer.address)
        break

client code

import enet
host = enet.Host(None, 1, 0, 0, 0)
peer = host.connect(enet.Address(b"localhost", 54301), 1)
while 1:
    event = host.service(1000)
    if event.type == enet.EVENT_TYPE_CONNECT:
        print("%s: CONNECT" % event.peer.address)
        break

from pyenet.

Amerikranian avatar Amerikranian commented on August 11, 2024

network.zip
I can't get the code styling right so... here you go. This folder contains my client and server code in different files

from pyenet.

aresch avatar aresch commented on August 11, 2024

What is the issue that you're experiencing?

from pyenet.

Amerikranian avatar Amerikranian commented on August 11, 2024

The issue is that the client seems to connect fine, but the server does not recognize that somebody has, in fact, connected. You will see that I tell the interpreter to print any event that is not of type none out on the screen, and when the client connects to it, the server output stays blank. The expected output is for it to detect the connection and the fact that the client promptly leaves as soon as it is connected. The last part is on purpose, I wanted to experiment with sending data later after I managed to successfully connect.

from pyenet.

aresch avatar aresch commented on August 11, 2024

Your code looks similar to what is in the test_client.py and test_server.py code. Do those work? Also, I'd suggest not passing 0 into host.service() in your server code as it will cause a tight spin.

from pyenet.

Amerikranian avatar Amerikranian commented on August 11, 2024

The test_client and test_server work properly, by which I mean I can connect, and the client shuts down the server. That's what makes this weird. Literally, I pretty much copied the test_client and test_server and edited them to just do connections.
What value would you suggest me pass into the service method? I thought 0 was the best and most quickest response the server will have towards the received packets

from pyenet.

aresch avatar aresch commented on August 11, 2024

host.service() will return when an event is posted, so it just depends on if you need to do anything else in your loop. 1000ms seems like a reasonable value.

So the reason you're not getting the event on the server side is that you need to call host.service() once more on the client side before exiting.

If you change your client code to the following, it should work as expected:

import enet
host = enet.Host(None, 1, 0, 0, 0)
peer = host.connect(enet.Address(b"localhost", 54301), 1)
while 1:
    event = host.service(1000)
    if event.type == enet.EVENT_TYPE_CONNECT:
        print("%s: CONNECT" % event.peer.address)
        host.service(0)
        break

I don't really have a good answer for you besides that there may be something to do with the handshake that's not being done in the client without the additional host.service() call.

Hope this helps.

from pyenet.

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.