Commits

Szymon Wróblewski  committed 9a9ebaa

updated documentation and examples

  • Participants
  • Parent commits 3b08ab1

Comments (0)

Files changed (7)

File doc/source/api/index.rst

                       print 'received:', e.message
    
    .. note::
+      
+      To use events you need to enable them with :func:`.init`
+   
+   .. warning::
    
       If you plan to change value of :const:`NETWORK` with
       :func:`.init`, then use:: 
          
          import pygnetic.event as event
          # rather than
-         # from pygnetic.event import NETWORK # wrong
+         # from pygnetic.event import NETWORK
 
 
 :mod:`handler` Module

File doc/source/conf.py

 # Add any Sphinx extension module names here, as strings. They can be extensions
 # coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
 #extensions = ['sphinx.ext.autodoc', 'sphinx.ext.viewcode']
-extensions = ['sphinx.ext.autodoc', 'sphinx.ext.viewcode', 'sphinx.ext.intersphinx']
+extensions = ['sphinx.ext.autodoc',
+              'sphinx.ext.viewcode',
+              'sphinx.ext.intersphinx',
+              ]
 
 # Add any paths that contain templates here, relative to this directory.
 templates_path = ['_templates']

File doc/source/examples.rst

+Examples
+========
+
+.. literalinclude:: ../../test_server.py
+
+.. literalinclude:: ../../test_client_2.py

File doc/source/index.rst

 **pygnetic** is a library designed to help in the development of
 network games and applications in `Pygame <http://www.pygame.org>`_.
 
+
+Features
+--------
+
+* Two approaches to handle network events
+   * generating events in pygame queue
+   * using handler classes
+* Efficient packaging of data through the message system
+* Support for multiple network and serialization libraries
+
+
 Contents
 --------
 
    :glob:
 
    api/index
+   examples
    license
 
+
+Installation
+------------
+
+**pygnetic** can be installed with
+`windows installer <http://pypi.python.org/pypi/pygnetic/#downloads>`_
+or with `pip <http://www.pip-installer.org>`_::
+
+   pip install pygnetic
+
 Optional requirements
 ---------------------
 
 * `pyenet <http://code.google.com/p/pyenet/>`_
 
 
-Installation
-------------
+Resources
+---------
 
-TODO
-
-Usage
------
-
-TODO
-
-
-Why should I use this module instead of X ?
--------------------------------------------
-
-TODO
-
-
-Support
--------
-
-TODO
-
-
-Development
------------
-
-The source code is hosted on
-`Bitbucket <https://bitbucket.org/bluex/pygnetic>`_::
-
-   hg clone https://bitbucket.org/bluex/pygnetic
-
-Development blog can be found here: http://pygame-networking.blogspot.com
+* Package on PyPI -- http://pypi.python.org/pypi/pygnetic
+* Repository on Bitbucket -- https://bitbucket.org/bluex/pygnetic
+* Documentation -- http://pygnetic.readthedocs.org
+* Development blog -- http://pygame-networking.blogspot.com
 
 
 Credits

File test_client_2.py

+"""Echo client"""
+
 import random
 import logging
 import pygnetic as net
         self.in_counter = 0
 
     def net_echo(self, message, **kwargs):
-        channel = kwargs.get('channel', 0)
-        logging.info('Received message @ch%d: %s', channel, message)
+        logging.info('Received message: %s', message)
         self.in_counter += 1
+        if self.in_counter == 10:
+            self.connection.disconnect()
 
     def update(self):
         if self.out_counter < 10 and self.connection.connected:
             logging.info('Sending: %s', msg)
             self.connection.net_echo(msg, self.out_counter)
             self.out_counter += 1
-        if self.out_counter == 10 and self.in_counter == 10:
-            self.connection.disconnect()
 
 
 def main():
-    net.init(logging_lvl=logging.DEBUG, n_module='socket')
+    net.init(logging_lvl=logging.DEBUG)
     net.register('echo', ('msg', 'msg_id'))
     client = net.Client()
-    connection = client.connect("localhost", 54301)
+    connection = client.connect("localhost", 1337)
     handler = EchoHandler()
     connection.add_handler(handler)
-    while True:
-        client.update()
-        handler.update()
+    try:
+        while handler.in_counter < 10:
+            client.update()
+            handler.update()
+    except KeyboardInterrupt:
+        pass
 
 
 if __name__ == '__main__':

File test_client_3.py

     pygame.display.flip()
 
     # Network init
-    net.init(events=True, logging_lvl=logging.DEBUG, n_module='socket')  # enable Pygame events
+    net.init(events=True, logging_lvl=logging.DEBUG)  # enable Pygame events
     echo = net.register('echo', ('msg', 'msg_id'))
     client = net.Client()
     connection = None
                             connection.disconnect()
                             connection_status(screen, (140, 38), False)
                     else:
-                        connection = client.connect("localhost", 54301)
+                        connection = client.connect("localhost", 1337)
                         connection_status(screen, (140, 38), False)
                 if e.key == K_l:
                     limit = not limit

File test_server.py

+"""Echo server"""
+
 import logging
 import pygnetic as net
 
 
 class EchoHandler(net.Handler):
     def net_echo(self, message, **kwargs):
-        channel = kwargs.get('channel', 0)
-        logging.info('Received message @ch%d: %s', channel, message)
+        logging.info('Received message: %s', message)
         msg = message.msg.upper()
+        logging.info('Sending: %s', msg)
         self.connection.net_echo(msg, message.msg_id)
 
 
-class Server(net.Server):
-    handler = EchoHandler
-
-
 def main():
-    net.init(logging_lvl=logging.DEBUG, n_module='socket')
+    net.init(logging_lvl=logging.DEBUG)
     net.register('echo', ('msg', 'msg_id'))
-    server = Server(port=54301)
+    server = net.Server(port=1337)
+    server.handler = EchoHandler
     logging.info('Listening')
-    run = True
-    while run:
-        server.update(1000)
+    try:
+        while True:
+            server.update(1000)
+    except KeyboardInterrupt:
+        pass
 
 
 if __name__ == '__main__':