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

Rene Dudfield illumen at yahoo.com
Sat Jun 28 17:28:51 PDT 2003


Ling Lo wrote:

>enet-discuss-bounces at cubik.org wrote:
>  
>
>>Hello,
>>
>>I was wondering how to send data from the server to a specific client?
>>
>>I got broadcast from the server to the client working ok.  But later I
>>want to be able to have multiple clients connect to the server and
>>have the server send data to only specific clients.
>>
>>Also, I do a peer.send(0,"a message", 0) from the client, but the
>>server doesn't seem to get the message.
>>
>>Thanks for any hints :)
>>    
>>
>
>Hiya,
>
>It's worth setting the reliable flag:
>
>peer.send(0, line, enet.FLAG_RELIABLE)
>
>To get the peer object for the client, store the peer object when the client
>connects, e.g.:
>
>            # Handle networking
>            result, event = self.host.service(ENetServerPeriod)
>            if True == result:
>                if enet.EVENT_CONNECT == event.type:
>                    # Peer has connected
>                    self.unnamedclientlist.append(event.peer)
>
>Hope this helps
>--
>  |   Ling Lo
>_O_O_
>
>_______________________________________________
>ENet-discuss mailing list
>ENet-discuss at cubik.org
>http://lists.cubik.org/mailman/listinfo/enet-discuss
>
>  
>
Hey,

thanks for your reply :)


I get a segfault when I do:
print dir(event.peer)

on the connection event.  See below for a gdb traceback.



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?


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?

Attached are some .py files which illistrate my problems.


Any help appreciated :)









(gdb) run atest_networking_enet.py server
Starting program: /usr/bin/python atest_networking_enet.py server
(no debugging symbols found)...(no debugging symbols found)...[New 
Thread 16384
(LWP 1191)]

(no debugging symbols found)...(no debugging symbols found)...
(no debugging symbols found)...(no debugging symbols found)...
(no debugging symbols found)...(no debugging symbols found)...
RUNNING: server
connected
(no debugging symbols found)...
Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 16384 (LWP 1191)]
enet_PeerObject_GetAttr (self=0x81276e0, attr_name=0x810b990) at 
pyenet.c:617
617	    Py_INCREF(attr);
(gdb) where
#0  enet_PeerObject_GetAttr (self=0x81276e0, attr_name=0x810b990)
    at pyenet.c:617
#1  0x08055fc7 in PyObject_GetAttr ()
#2  0x08056b5b in PyObject_Dir ()
#3  0x080d662f in _PyBuiltin_Init ()
#4  0x080d3fca in PyCFunction_Call ()
#5  0x08075fc4 in Py_MakePendingCalls ()
#6  0x080769b3 in PyEval_EvalCodeEx ()
#7  0x080777ef in PyEval_CallObjectWithKeywords ()
#8  0x08075f1f in Py_MakePendingCalls ()
#9  0x080769b3 in PyEval_EvalCodeEx ()
#10 0x080777ef in PyEval_CallObjectWithKeywords ()
#11 0x08075f1f in Py_MakePendingCalls ()
#12 0x080769b3 in PyEval_EvalCodeEx ()
#13 0x080777ef in PyEval_CallObjectWithKeywords ()
#14 0x08075f1f in Py_MakePendingCalls ()
#15 0x080769b3 in PyEval_EvalCodeEx ()
#16 0x08078c06 in PyEval_EvalCode ()
#17 0x0809bc71 in PyRun_FileExFlags ()
#18 0x0809b557 in PyRun_SimpleFileExFlags ()
#19 0x080532bc in Py_Main ()
#20 0x08052e7f in main ()
#21 0x40164a51 in __libc_start_main () from /lib/libc.so.6





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.



For the disconnection problem:

python -u atest_networking_enet.py server > /tmp/asdfasdf

Then run a client one more time than the peercount is set to (7 times 
with the attached code).
python -u atest_networking_enet.py evil_client








More information about the ENet-discuss mailing list