Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
I need to make a chess multi-player game that works over the internet. I am a beginner to programming and networking alike, although I have managed the GUI based chess platform.
Now I need to overcome the challenge of configuring the game over the internet.
In order to do that, I would like to use a third party application or software (anything but socket programming) to make the python programs running on two machines talk to each other. What I am hoping to do is, that whenever someone makes a move, I want to send a string/list of the updated coordinates of his/her chess pieces over the internet to the second player, so that he can see what move has been made. Can anyone please tell where to start from or what to read regarding the same? Is the idea of sending the updated string/ list of coordinates feasable using an open source chat utility like telepathy?
You'd want to use the socket module. Example programs. It really isn't so difficult to use socket, basically the server end has to bind(), listen(), then accept() and the client has to simply connect(). From there recv() and sendall() can be used to receive and send data respectively. If you really don't want to use socket, then you could use a chat protocol like IRC or XMPP.
A chat/IM solution seems like a fine idea.
For chat/IM, you could use Jabber/XMPP. You would either need to set up your own server or find someone hosting one for the public. Setting up a Jabber server is fairly easy, you can use OpenFire for example. For connecting to Jabber, you could use python xmpp libraries to send and receive the messages. This might be the simplest approach because the Jabber libraries tend to be very easy to use. (I've done it in Java and .NET, not python, though).
Another approach would be to use something like twitter messaging. See Python Twitter library: which one? for a recommendation for a library which supports direct messaging (which is what you need). The advantage of this, is that once you learn the twitter API, you don't need your own server.
This is a broad, opinionated question but my go-to network communication protocol in Python is Twisted's Perspective Broker. It's event driven, kind of complicated to setup and requires control of the program's event loop but it works great. It allows for two-way communication between the client and server, and has the convenience of remote objects.
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 1 year ago.
Improve this question
I have recently learned about sockets, their differences to for example HTTP or AJAX and used it in some of my python applications for learning-purposes by setting them up via the sockets module. I now looked into using them together with flask in a web app (compared to previously only running in the console/terminal window) and noticed that nearly all examples, tutorials and documentation use socket.io . Why is that? And how does it behave differently to the sockets module?
(Note: I don´t want to use any JS in the web app, just python, as it´s what I am familiar with and I am only throwing together a proof of concept)
sockets and socket.io have in common that they allow two application to communicate directly over a network. However, they are very different as they operate on entirely different layers of networks.
Sockets are defined on the transport layer and allow for a very direct way of communication, avoiding the complexities (but also lacking the functionality) of higher level protocols, like http and services defined on top of http. The sockets library allows you to work with this type of socket.
socket.io defines software "sockets" for JavaScript applications, but because the library became very popular (and works quite well), implementations now exists for many languages. However, it operates on top of http (as one of the possible transports, the whole truth is a bit more complicated). The 'sockets' in socket.io are sockets in that they allow direct point to point communication, but they operate at a much higher level of abstraction.
As for deciding which to use - it depends on what you're looking to communicate and who or what you need to communicate it with.
To understand why something operating on the transport layer is very different from something operating on the application layer, you should perhaps read up on the OSI model https://en.wikipedia.org/wiki/OSI_model
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 1 year ago.
Improve this question
WebRTC Peer to Server instead of Peer To Peer
I want to build a WebRTC Video and Voice Calling App.
However, I do not want a user to be able to connect directly to another user, as this brings unwanted security risks. So I think it makes more sense to implement the whole thing in such a way that all users (2 in this case) connect to a server, which then distributes the data and the users do not distribute it among themselves, so that, for example, the IP is publicly visible.
I don't want that:
So even I think this is the normal way you could do it I don't want to, because, how I said there are a lot of security risks that this kind of connection brings with it.
I want that:
I've heard that Discord, for example, does exactly what I show in the graphic (at least similarly). Can this be implemented? And if so, how? By the way, I used Python Django in the backend. I was wondering whether this could also be done with Python Django Channels. So is there an implementation in Django Channels that I can set up a WebRTC server? Many thanks in advance
You need to use a TURN relay server and set the RTCIceTransportPolicy to relay when creating the RTCPeerConnection in the browser. That will result in the media path matching your bottom diagram.
ALL public peer-to-peer communications use a server in the middle. Virtually every end-user computer in the world today sits behind a firewall and cannot be directly addressed from outside their network.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I know this is technically a duplicate question, but I believe it is valid since the original question was submitted 7 years ago and Python/web security has come a long way since then.
I would like to build a web app that allows users to input python code (through the Ace editor package) and then execute it in the browser using a python interpreter on the server. I cannot use pypy.js because I need to use numpy, pandas, and matplotlib. Essentially I would like to make my own Codecademy (I am a teacher and would like to create Codecademy-like courses for my students). Sadly the create-a-course thing Codecademy mentioned at one point has come to nothing.
I'm using Flask, but I could learn Django if that would be easier.
What is the best way to allow my users to run the python code without allowing them to affect the rest of the program or access files outside of what they're allowed to?
There were no fundamental changes in Python or web security the last 7 years. It is still suicidal to allow users to run code on your server.
However, what did change is the availability of lightweight VM solutions like docker.
For an example how this could work have a look at https://civisanalytics.com/blog/engineering/2014/08/14/Using-Docker-to-Run-Python/ . I will not reference this solution here as you will found other examples, even if this one goes away.
However, this might be more safe then running user code direct on your server, BUT
the user code is still running on your server. It might be not possible to escape the docker image, but a malicious user could still upload for eg. a denial of service tool and start an attack from your server. Or sniff your network traffic or whatever.
there are or at least might be ways to break out of the docker image.
For a controlled environment like a classroom those risks might be acceptable, but for a public server you would need a lot of security know how to further lock down the server and the docker image and filter available python functionality.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 5 years ago.
Improve this question
I am working on a homework project for a Networking class where we have to build a simple web based chat server in either C/C++ or Python. I chose Python because I thought it would be an easier language to implement the project in. We can use any material we find on the web, because it most likely won't have all the functionality that the project requires. In fact, the professor actually encouraged us to use material from the web including tutorials. He's not testing us on our ability to code rather our ability to implement networking code, and whether or not we fully understand the processes involved.
The project must handle multiple clients, and must be able to support multiple browsers, chrome, firefox, etc. A user needs to be able to type in an IP Address and a Port in the browser to connect. I just can't find any material to work with. I have found a little in C but nothing in Python.
Does anyone know of any complete tutorials out there? There are plenty for client/server command-based chats, but no browser based chats.
You can look at using TornadIO. Its a python implementation of Socket.io, for Tornado, Tornado is an event-driven python web server.
https://github.com/MrJoes/tornadio2
http://www.tornadoweb.org/
Socket.io is a cross-browser solution to socket/socket-like connections from the web client to the server. This will pretty much give you all the tools you need to do a chat server since it supports pub-sub subscriptions and messages. The nice thing about using socket.io for your purposes is that it tries a number of transports in order to ensure that new and old browsers can all communicate: Websocket, Flashsocket, xhr polling, jsonp, htmlfile. They all are attempted and used in a way that looks the same to the client.
Tornadio2 is the newer version that is compatible with the newer Socket.io 0.7+. This version added a lot of features that broke compatibility with 0.6. However, the original TornadIO contains a chatroom example which you could review and translate pretty easily to the newer version to get you started:
https://github.com/MrJoes/tornadio/tree/master/examples/chatroom
As far as I can understand, the home work given is let people gets hands on activity with network programming. So might take a look at www.twistedmatrix.com, few example use case of twisted
Chat comet site using python and twisted,
http://lists.canonical.org/pipermail/kragen-hacks/2005-April/000409.html,
http://code.google.com/p/twisted-chat-example/.
This one uses plain socket programming http://code.activestate.com/recipes/531824-chat-server-client-using-selectselect/,
http://ankurs.com/2008/05/creating-a-simple-chat-application-with-python/.
This one is based on gevent.
For simple chat room emulation without use of socket programming, here is the example gummi.
A real life use case at sourceforge.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
I am a web developer (PHP/Javascript) and to increase my skill set, I would like to learn a new language. I have a simple test project in mind for this, so I can learn more about (wireless) networks and Linux, something I'm interested in as well.
I have specced out my project like this:
Look at all the open wireless networks in my area, and determine which one is the least busy (i.e. has the least data traffic), then list its ESSID. Do this by putting the wireless interface in monitor mode, and collect statistics about which access point receives/transmits the least TCP packets.
I think this would be a fun, simple way to get the "best" access point to connect to. I'm sure there are better ways to reach that goal, but this would cover all the things I want to learn about.
I am working in Ubuntu, and would like to learn Python or Ruby with this project. I have done a bit of research, and I think I'll need (a wrapper for) libpcap to sample the amount of data. I would also need to address iwconfig to change to the next channel, and look for packets there.
So, my question is: is there an ideal language for this? Is it possible to do this "inside" a language, without having to break out of it to issue a command line command like "iwconfig"? Any advice in general?
My preference is Ruby, and that is because it is my preference. However, there are lots of libraries availble in each language. See:
http://www.scribd.com/doc/56319311/Programming-Wireless-Security-32813
also
Which of these scripting languages is more appropriate for pen-testing?
I don't know much about Ruby, but I'm sure that Python could do what you want. In regards to stepping down into OS/CLI land, I would have a look at the os and subprocess modules. The subprocess module will let you call arbitrary binaries (such as iwconfig) from python and collect their results.
Python is fun to learn. Good luck.