sockets module vs socket.io module [closed] - python

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

Related

WebRTC Peer to Server instead of Peer To Peer [closed]

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.

communicating with another python program over the internet [closed]

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.

A tutorial for a web-based chat server in Python [closed]

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.

Finding the least busy open wireless network: which language to pick for this weekend project? [closed]

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.

Good high-level python ftp/http lib? [closed]

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 4 years ago.
Improve this question
I'm looking for a good, high-level python ftp client/server library. I'm working on a project that has "evolved" a small http/ftp library on top of ftplib/urllib/urllib2 from what was originally one function, and almost none of it was designed to be built upon. So now it's time to refactor kind of seriously, and I'd like to just switch to a library. The thing I'd most like to not deal with is robust-retry logic (like, keep retrying 15 times, or keep retrying until 12pm).
The problem that we've got right now is that we have about 10 separate grab() and put() functions. Aesthetically speaking, I'd rather have one of each with optional arguments along the lines of try_until=datetime(2009, 10, 7, 19) or retrys=15. We work with both binary and text data, so the functions would have to be reasonably smart about that. And we do way more grabbing than putting, so I can deal without the puts.
urlgrabber looks like exactly what I want, but there doesn't seem to have been any development for the last couple years and I'm not sure how compatible it is with 2.6. Anybody got much experience with this? Or opinions?
URLgrabber appears to be very mature, and since it's used by yum (and thus many Unix systems), I would expect it to be very stable. Python 2.x is largely backward compatible. You might encounter some warnings, but I would expect it to work suitably under Python 2.6.
Depending on the sort of application you are writing, you might want to consider twisted python, as it has http server and client code built in. However, it is a rather large departure from standard procedural python programming.
The big advantage of twisted for you is that it can handle your client requests in the background, handles retries and is very scalable.
Update
For a quick script that interacts with servers, see this serverfault answer:
https://serverfault.com/questions/66336/script-automation-login-enter-password-run-commands-save-output-locally
It recomends the tool expect
Expect is a tool for automating
interactive applications such as
telnet, ftp, passwd, fsck, rlogin,
tip, etc. Expect really makes this
stuff trivial. Expect is also useful
for testing these same applications.
And by adding Tk, you can also wrap
interactive applications in X11 GUIs.
Expect can make easy all sorts of
tasks that are prohibitively difficult
with anything else. You will find that
Expect is an absolutely invaluable
tool - using it, you will be able to
automate tasks that you've never even
thought of before - and you'll be able
to do this automation quickly and
easily.
Sounds good to me!

Categories

Resources