2019-09-30 03:03:52 (edited by amerikranian 2019-09-30 04:05:19)

Pyenet appears to be another python networking lib. (pip install pyenet). It's git repo can be found here
Could anyone provide a well-commented example of how the lib is used? The docs appear to be either for c or c++ when using it, can't tell which one.

2019-09-30 09:21:45

So I took a quick look at it.
There is some examples on the github page you provided which seem pretty self explanatory, and the link below seems to tell you more about the documentation.
A little work with dir() should tell you how to make the jump between the tutorial and python (if necessary).
http://enet.bespin.org/Tutorial.html

Be aware this is a UDP library. If you're only starting with networking in python, I recommend you start with the socket module, which not only comes by default, but is far easier to understand. Then you can upgrade to something like twist i think it is called.
both socket and twist, to the best of my knowledge, support both TCP and UDP network work.
HTH

Nathan Smith
Managing Director of Nathan Tech
It's not disability
It's ability!

2019-09-30 17:22:49

So I've been trying to see how this works and still, no luck. Here's my server code:

import enet
host = enet.Host(enet.Address(b"localhost", 8080), 1, 0, 0)
while 1:
 event = host.service(0)
 if event.type != enet.EVENT_TYPE_NONE:
  print("Connection")

Here's my client code:

import enet, time
host = enet.Host(None, 1, 0, 0)
peer = host.connect(enet.Address(b"localhost", 8080), 1)
while 1:
 event = host.service(0)
 if event.type == enet.EVENT_TYPE_CONNECT:
  print("Connection...")
  time.sleep(3)
  break

If you run this, you'll see that the client indeed has established a connection, but the server doesn't pick that up. Why not?

2019-09-30 19:30:01

I'm curious, is there a reason you want to use enet over twist or socket?
I'm looking at the c documentation, which to be frank is good but only if you know how to hop between python and c.
If you just want a UDP server, use socket, or twist, because they're way more documented.
The only reason I can see to use ENET is to support BGT, which may not work anyway as I vaguely recall BGT uses an outdated version of ENET.
HTH

Nathan Smith
Managing Director of Nathan Tech
It's not disability
It's ability!

2019-09-30 20:06:30 (edited by amerikranian 2019-09-30 20:06:48)

I gathered that pyenet has a UDP support which can still do the sending of reliable packets, i.e, waiting for a client to acknowledge the data before proceeding. I don't want to use purely TCP because in some cases I might care for the latest information only, but I don't want to use only UDP because sometimes I would like preciseness with the data I'm sending and receiving

2019-10-01 04:45:40

The socket module, python's low-level interface to the BSD sockets API, can be far from simple to use and understand. Games require much more than connecting to a server, receiving a quick status of fixed length and promptly closing.
Also it's twisted, not twist. Twist as you call it is comparatively easy to understand, even if I personally prefer other solutions for games. Lack of experience is one thing, misinformation is another. Simple google search either way.
I get you're trying to help man, that's great and appreciated I'm sure. But in this case your lack of experience is doing more harm than good. What you're doing here is analogous to telling a beginner runner to start out with a marathon, without ever running yourself. It simply doesn't make much sense.

Anyway, Enet aims to provide a high-level layor over UDP communication, reducing the need to play around with lower-level conversation in addition to adding reliability.
You're gonna have to dig a bit deeper here, since pyenet is nothing more than a wrapper. Providing documentation for wrappers is unconventional since most people don't feel like re-inventing the wheel.
The docs are found at:
http://enet.bespin.org/

You obviously won't be getting syntactical equivalents, but these should be enough to give an idea of the API. Just forget about pointers and similar C constructs not present in python.

2019-10-02 01:28:47 (edited by amerikranian 2019-10-02 01:29:35)

So, I have tried to follow the tutorial on the official website and still, no luck. I have ripped out the code from the example server and client the github repo had, and still no luck. Oddly, when running the example, the thing seems to work... so what is wrong with this?

#client code:
import enet, time
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)
        time.sleep(2)
        break

#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(1000)
    if event.type == enet.EVENT_TYPE_CONNECT:
        print("%s: CONNECT" % event.peer.address)
        break

If you run this, you'll see that the client has supposidly connected to the server, but the server output stays blank, even though you clearly see that I'm telling it to print some info in the code.

2019-10-02 07:17:25 (edited by pauliyobo 2019-10-02 07:17:52)

Twisted isn't hard to learn, but you have to learn concepts such as protocols, factories, and reactors. Pyenet compared to the 3 seems the easiest one to get started with.

Paul

2019-10-02 13:58:33

For anyone interested, I managed to get it working with the help from the creator himself. Oddly enough, it required an additional host.service call after the connection was established. Here's the client code just in case somebody wants to try and figure out why we need another poll for events, lol.

import enet, time
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)
        time.sleep(2)
        break