Comments (7)
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.
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.
What is the issue that you're experiencing?
from pyenet.
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.
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.
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.
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)
- Support for intercept callback HOT 1
- PyPi package 404s HOT 1
- enet web address update HOT 4
- Windows compilation instructions HOT 3
- Callbacks swallow exceptions HOT 2
- Unable to send packets? HOT 1
- Is it possible to connect pyenet to enet in C++ program? HOT 1
- upload wheels to Pypi HOT 4
- what is enet_host_destroy in pyenet? HOT 1
- CheckSum
- how to set host checksum?
- settings
- Linux and Windows build error - _ENetPeer struct HOT 1
- Using pyenet in repl.it will just stay in the connecting state.
- How do i set ENet Checksum?
- Socket.send wrapper for enet_socket_send HOT 4
- enet_crc32?
- Address() creation with non-byte host argument HOT 1
- Is pynet still alive? HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pyenet.