[ENet-discuss]pyenet: how to send data from server to client.

Ling Lo ling at slimy.com
Mon Jul 21 02:07:39 PDT 2003


Rene Dudfield [illumen at yahoo.com] wrote:
> Ling Lo wrote:
>
> I get a segfault when I do:
> print dir(event.peer)

Fixed...  I was incrementing reference count on a null attributes.  Oops.
I've attached the patch, to be executed in /enet/pyenet.  Still not too sure
if I'm doing the right thing, I can't get the new-style classes thing going
(where you can set attributes on any object).

> A seperate issue.  I get a bit of packet loss when using the reliable
> packets.  I think it may be because I use a very low value for the
> service call.  This is so that my game can continue running whilst
> networking is being handled(without using a seperate thread).  Perhaps
> the enet.FLAG_RELIABLE is not being passed through as the same number
> as the c api expects?  Or maybe there is a problem with the c api?

Packet loss is to be expected over WAN, it's part of normal operations.  I'd
be really surprised if you get some problem in a local loop.

> Another issue I have is to do with disconnecting clients.  If a client
> calls the disconnect method but does not wait around for the
> disconnect reply from the server, then the server still thinks the
> connection is open.  This can be repeated, leading onto the server
> not accepting anymore connections.  Is there a way to change the
> disconnection timeout?  Or maybe some other method of trying to
> prevent this type of abuse?

This is a general quirk of connectionless protocols.

How about adding a layer of authentication?  The client immediately sends
over login/password and if not valid gets disconnected (peer.disconnect)
within 2 seconds.  Also, raise the number of maximum hosts above the
expected number of playing clients and reserve them for admin.

> Attached are some .py files which illistrate my problems.
>
> Any help appreciated :)
>
>
> For the loss of reliable packets:
>
> python -u atest_networking_enet.py server > /tmp/asdfasdf
> python -u atest_networking_enet.py bench_client
> grep hi /tmp/asdfasdf | wc -l
>     998
>
> hi should be printed 1000 times.

I can't reproduce this...  Also, you imply you're doing this on the same
machine which shouldn't have any packet loss.  You can get packet loss
figures using:

   peer.packetloss

Also, roundtriptime is another handy peer attribute, they're in the pyenet's
incredibly brief documents.

Sorry about the utter lack of reply for a while, just slowly getting back
into my bedroom coding persona.
--
  |   Ling Lo
_O_O_
-------------- next part --------------
*** pyenet.c	2003/06/23 03:15:28	1.2
--- pyenet.c	2003/07/21 00:01:34
***************
*** 1,4 ****
--- 1,10 ----
+ #ifdef _DEBUG
+ #undef _DEBUG
  #include <Python.h>
+ #define _DEBUG
+ #else
+ #include <Python.h>
+ #endif
  #include "enet.h"
  
  // #define DO_LOG
***************
*** 68,74 ****
  
      attr = PyObject_GenericGetAttr(self, attr_name);
      // :TODO: Should this be DECREF?
!     Py_INCREF(Py_None);
      return attr;
  }
  
--- 74,81 ----
  
      attr = PyObject_GenericGetAttr(self, attr_name);
      // :TODO: Should this be DECREF?
!     if (NULL != attr)
!         Py_INCREF(Py_None);
      return attr;
  }
  
***************
*** 104,110 ****
      0, // (ternaryfunc)enet_HostType_Call,  /*tp_call*/  // **** FUNCTIONCALL CATCHER
      0,                      /*tp_str*/
      enet_EventObject_GetAttr, /*tp_getattro*/
!     0,                      /*tp_setattro*/
      0,                      /*tp_as_buffer*/
      Py_TPFLAGS_DEFAULT,     /*tp_flags*/
      0,                      /*tp_doc*/
--- 111,117 ----
      0, // (ternaryfunc)enet_HostType_Call,  /*tp_call*/  // **** FUNCTIONCALL CATCHER
      0,                      /*tp_str*/
      enet_EventObject_GetAttr, /*tp_getattro*/
!     PyObject_GenericSetAttr,  /*tp_setattro*/
      0,                      /*tp_as_buffer*/
      Py_TPFLAGS_DEFAULT,     /*tp_flags*/
      0,                      /*tp_doc*/
***************
*** 419,426 ****
      0,       /*tp_hash*/
      0, // (ternaryfunc)enet_HostType_Call,  /*tp_call*/  // **** FUNCTIONCALL CATCHER
      0,                      /*tp_str*/
!     0, //(getattrofunc)enet_HostType_GetAttrO,  /*tp_getattro*/
!     0,                      /*tp_setattro*/
      0,                      /*tp_as_buffer*/
      Py_TPFLAGS_DEFAULT,     /*tp_flags*/
      0,                      /*tp_doc*/
--- 426,433 ----
      0,       /*tp_hash*/
      0, // (ternaryfunc)enet_HostType_Call,  /*tp_call*/  // **** FUNCTIONCALL CATCHER
      0,                      /*tp_str*/
!     PyObject_GenericGetAttr, /*tp_getattro*/
!     PyObject_GenericSetAttr, /*tp_setattro*/
      0,                      /*tp_as_buffer*/
      Py_TPFLAGS_DEFAULT,     /*tp_flags*/
      0,                      /*tp_doc*/
***************
*** 614,620 ****
  
      attr = PyObject_GenericGetAttr((PyObject*)self, attr_name);
      // :TODO: Should below be Py_DECREF???
!     Py_INCREF(attr);
      return attr ;
  }
  
--- 621,628 ----
  
      attr = PyObject_GenericGetAttr((PyObject*)self, attr_name);
      // :TODO: Should below be Py_DECREF???
!     if (NULL != attr)
!         Py_INCREF(attr);
      return attr ;
  }
  




More information about the ENet-discuss mailing list