Network in Python
Network in Python Hi guys.Tell me about working with the network in Python.What libraries, maybe you have examples?Thanks in advance! URL: http://forum.audiogames.net/post/400746/#p400746 -- Audiogames-reflector mailing list Audiogames-reflector@sabahattin-gucukoglu.com https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector
Re: Network in Python
Re: Network in Python There are a few ways to do it, [Sockets], also [Asyncio] in python 3, or if your looking for a library there's [Twisted Python], or if your more into web applications theres [Django]. URL: http://forum.audiogames.net/post/400812/#p400812 -- Audiogames-reflector mailing list Audiogames-reflector@sabahattin-gucukoglu.com https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector
Re: Network in Python
Re: Network in Python magurp244, I heard that for sockets, you need to know multithreading in Python. It's true? URL: http://forum.audiogames.net/post/400947/#p400947 -- Audiogames-reflector mailing list Audiogames-reflector@sabahattin-gucukoglu.com https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector
Re: Network in Python
Re: Network in Python @3, uh... no? You don't. I wrote a port scanner that uses no threads at all (though I wanted it to work in parallel, it failed). That was using good ol classic Python sockets, which was perfect for the job (anything else would've been overkill). For anything truly serious, multithreading is a given, no matter what your using. URL: http://forum.audiogames.net/post/400949/#p400949 -- Audiogames-reflector mailing list Audiogames-reflector@sabahattin-gucukoglu.com https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector
Re: Network in Python
Re: Network in Python Ethin, It's mean, if I want to use the Socket library, and I need several clients, I not need multithreading? URL: http://forum.audiogames.net/post/400959/#p400959 -- Audiogames-reflector mailing list Audiogames-reflector@sabahattin-gucukoglu.com https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector
Re: Network in Python
Re: Network in Python So, I read on the Internet.There are two libraries. socket and twisted.socket is a library in which I have to use multithreading, as I understood. Twisted higher level library.I looked at the example codes, and I'm terrified. In the Protocol class, I write a server program, as I understand it. But Factory...Where can I read about it, and how can I figure it out? After BGT it looks scary. URL: http://forum.audiogames.net/post/400972/#p400972 -- Audiogames-reflector mailing list Audiogames-reflector@sabahattin-gucukoglu.com https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector
Re: Network in Python
Re: Network in Python you don't always need multi threading. You could write a server with select and socket and you would deal with multiple clients anyway. URL: http://forum.audiogames.net/post/400985/#p400985 -- Audiogames-reflector mailing list Audiogames-reflector@sabahattin-gucukoglu.com https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector
Re: Network in Python
Re: Network in Python Hi,uhm, what will probably confuse you in Python's socket library is the blocking mode. If you're just reading through the socket api quickly, you might end up with the idea that the operations are blocking and therefore you need to implement some multithreading to compensate for this. Well, its just as easy as telling the socket library to work non-blocking instead, so you can handle loads of clients with a simple thread, as long as your functions/methods are fast enough to prevent incoming requests from waiting too long. The Python multithreading is... well, it creates multiple python instances and therefore allows to process methods and functions in parallel, but its technically more multiprocessing than multithreading, since those threads won't actually be executed on the different cores of your processor, they will still run on one single thread. Writing true multithreaded programs in Python is rather complicated and shouldn't worry you too much if you're just a newbie migrating from BGT right now.I'd recommend to play around a bit with sockets in Python, but if you're planning to program something consistant and stable, consider using a well-known library like Twisted. You'll find loads of example on the net, and yeah, its of course more complicated than BGT. BGT does many things really basic and simple, just to simplify audio game programming, but it doesn't do you any good when you're planning to learn real programming.Best Regards.Hijacker URL: http://forum.audiogames.net/post/400992/#p400992 -- Audiogames-reflector mailing list Audiogames-reflector@sabahattin-gucukoglu.com https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector
Re: Network in Python
Re: Network in Python Hijacker, Can you advise how I can learn Twisted? URL: http://forum.audiogames.net/post/401039/#p401039 -- Audiogames-reflector mailing list Audiogames-reflector@sabahattin-gucukoglu.com https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector
Re: Network in Python
Re: Network in Python There's some guides [here], and [here] and some example scripts [here]. There's also the [documentation], with a slightly more up to date PDF [here].I've played around with twisted a bit before, so I have a few examples around as well. Some of the more recent ones haven't been fully tested, mostly with timeouts and over open networks, but they handled more game oriented things like finding servers with UDP broadcasting across local networks, TCP/IP client/server setup with host migration, etc. Oh, and watch out for floating point determinism and desync, heh. URL: http://forum.audiogames.net/post/401044/#p401044 -- Audiogames-reflector mailing list Audiogames-reflector@sabahattin-gucukoglu.com https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector
Re: Network in Python
Re: Network in Python There's some guides [here], and [here] and some example scripts [here]. There's also the [documentation], with a slightly more up to date PDF [here].I've played around with twisted a bit before, so I have a few examples around as well. Some of the more recent ones haven't been fully tested, mostly with timeouts and over open networks, but they handled more game oriented things like finding servers with UDP broadcasting across local networks, TCP/IP client/server setup with host migration, etc. Oh, and watch out for floating point determinism and desync, heh. URL: http://forum.audiogames.net/post/401045/#p401045 -- Audiogames-reflector mailing list Audiogames-reflector@sabahattin-gucukoglu.com https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector
Re: Network in Python
Re: Network in Python There's some guides [here], and [here] and some example scripts [here]. There's also the [documentation], with a slightly more up to date PDF [here].I've played around with twisted a bit before, so I have a few examples around as well. Some of the more recent ones haven't been fully tested, mostly with timeouts and over open networks, but they handled more game oriented things like finding servers with UDP broadcasting across local networks, TCP/IP client/server setup with host migration, etc. URL: http://forum.audiogames.net/post/401045/#p401045 -- Audiogames-reflector mailing list Audiogames-reflector@sabahattin-gucukoglu.com https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector
Re: Network in Python
Re: Network in Python Twisted is great, There's another library called podSixNet which is usually used for games network handlings. URL: http://forum.audiogames.net/post/401095/#p401095 -- Audiogames-reflector mailing list Audiogames-reflector@sabahattin-gucukoglu.com https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector
Re: Network in Python
Re: Network in Python magurp244, I read these links. It is very difficult. Synchronous and psychic programming ...I should look for simpler information. URL: http://forum.audiogames.net/post/401134/#p401134 -- Audiogames-reflector mailing list Audiogames-reflector@sabahattin-gucukoglu.com https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector
Re: Network in Python
Re: Network in Python It's harder than in C#. But I'd like to deal with it.For example, why do I need Factory in Twisted? How it works?If you know Twisted, how did you learn it? URL: http://forum.audiogames.net/post/401374/#p401374 -- Audiogames-reflector mailing list Audiogames-reflector@sabahattin-gucukoglu.com https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector
Re: Network in Python
Re: Network in Python regarding podsixnet, if you are looking for tcp sockets in your game, it is really really good.but, if you are looking for a lib that can handle udp, then podsixnet is not for you. URL: http://forum.audiogames.net/post/401389/#p401389 -- Audiogames-reflector mailing list Audiogames-reflector@sabahattin-gucukoglu.com https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector
Re: Network in Python
Re: Network in Python Mostly by playing around with the examples, also reading through [1500 archers] for a better understanding of lock step networking and such. In simplist terms, the factory handles the connection process and calls a client class for handling connections when another computer reaches out, for example here's a basic TCP/IP server:from twisted.internet import reactor, protocol class Echo(protocol.Protocol): """This is just about the simplest possible protocol""" def dataReceived(self, data): "As soon as any data is received, write it back." print("Client Said: ",data) self.transport.write(data) def main(): """This runs the protocol on port 8000""" factory = protocol.ServerFactory() factory.protocol = Echo reactor.listenTCP(8000,factory) reactor.run() # this only runs if the module was *not* imported if __name__ == '__main__': main()In this example, Main() is called which sets up the initial server. The server factory handles the process of establishing a connection, and assigns a connecting computer a protocol class for sending and recieving data, in this case, the Echo() class above. Then the reactor listens on port 8000 for any computer that tries to connect, if one does it passes it to the factory to handle the connection and assigns it the Echo class to communicate with it. Now, for the client example:from twisted.internet import reactor, protocol class EchoClient(protocol.Protocol): """Once connected, send a message, then print the result.""" def connectionMade(self): self.transport.write(b"hello, world!") def dataReceived(self, data): "As soon as any data is received, write it back." print("Server said:", data) self.transport.loseConnection() def connectionLost(self, reason): print("connection lost") reactor.stop() # this connects the protocol to a server running on port 8000 def main(): f = protocol.ClientFactory() f.protocol = EchoClient reactor.connectTCP("localhost", 8000, f) reactor.run() # this only runs if the module was *not* imported if __name__ == '__main__': main()This client calls main(), which establishes the Client Factory, and then tries to connect to a server on port 8000, if it succeeds it calls the client factory to handle setting up the connection with the server and assigns the EchoClient() class to handle sending and recieving data. So, so sum it up: both the client and the server listen and reach out through ports, when a connection is detected they use factories to handle those incoming connections, and then assign them class handlers for sending and recieving data. When someone connects to a server, it creates an Echo class which you can stuff in a list somewhere, and then to use it you do something like:self.clients[0].send("message for client one.") URL: http://forum.audiogames.net/post/401397/#p401397 -- Audiogames-reflector mailing list Audiogames-reflector@sabahattin-gucukoglu.com https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector
Re: Network in Python
Re: Network in Python kianoosh, visualstudio,I'm focused on Twisted, but it is difficult to understand.I looked at the implementation of sockets in C#, it is more simple than in Python.magurp244,Thank you so much for this! Already many times you helped me.I didn't understand the details about the factory. I understud that the factory calls the server and client event classes. But thanks, it helped me. URL: http://forum.audiogames.net/post/401406/#p401406 -- Audiogames-reflector mailing list Audiogames-reflector@sabahattin-gucukoglu.com https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector