Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have no experience doing anything like this, but I want to make a little email server that will only be accessed from the local machine through the Mail app in OS X. I know that the Mail app lets you connect to an email server with the POP3 protocol, and I have a reference manual on POP3 so I know how it all needs to work. I am just not sure of the best way to write this. I know python has smtpd, which I can use for receiving mail from the Mail app. Can I just use the SocketServer module, subclass BaseRequestHandler, read from the self.request socket until I get a CRLF, split the data by spaces, then use the first item in the list as keyword and apply the corresponding function to the rest of the list, and finally return the status + results? Or is it more complicated than that?
--EDIT--
I forgot to mention that I wanted to do this in pure python.
Implementing protocols and a working server is always more complicated than "just a few lines of code". Try twisted It has implementations for many internet protocols and working examples. Here's an example: http://pepijndevos.nl/twisted-pop3-example-server/
You can use pypopper python recipe to readily implement the pop3 server functionality.
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I am trying to create a utility using Python (3) that, among other things, needs to look at and manage socket usage ON WINDOWS (no, I really don't care if it works on other OS's).
Looking at socket usage: To be clear, I don't want to create a socket or bind to an existing one, I want to be able to get a full list of what sockets are open and what programs have opened them. If you're not sure about what I mean, take a look at TCPView, which does exactly what I'm talking about.
Managing socket usage: Basically, I want to be able to stop programs from connecting from the internet, if necessary. I would assume that the easiest way to do this is to use os.system() to add a new rule to the Windows Firewall, but as that doesn't seem too elegant I'm open to suggestions.
As that's obviously not all the utility will do, I would prefer a library/module of some sort over a 3rd-party program.
You can launch the command "netstat -nabo" to get the list of all active connections & parse the output to get the source, destination, process name & ID. There is no straight forward method to get the active connections in python. You can also get the same information from python invoking iphlpapi. To block or allow a connection windows has command line to add/remove rule from windows firewall.
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.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Improve this question
I am currently putting some code together to create a TCP/IP client which will have to communicate with an existing network server (Local not Internet). The server code is out of my control as it is already in place. I seem to have test code that works, at least the server recognises that a client with the relevant IP address is making a connection, however, on first connection the server sends out an Identify command to confirm the client is valid:
IDENTIFY_#
This is my problem. The client code has to be written in Python and obviously #'s seem to create an issue. My understanding (being new to Python) is that they are only used for comments and all of the posts and books I have read seem to say the same. Unfortunately I have to respond with strings that also possess #'s as termination characters for data sets so it makes things twice as problematic. Is it possible to get Python to recognise a # for what it is and not throw a wobbly because it assumes it is a comment?
If the # symbol is within a string literal, it shouldn't be interpreted as a comment.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 8 years ago.
Improve this question
I am quite new to Python and recently I wanted to send some files using Python. I quickly found out about sockets. But I searched for ready-made solution, because I thought client-server communication is such a common use, there must exist some kind of library (or maybe it's just because of my Java background and I got used to it:D). All answers about sending files I found mentioned sockets and that 'you have to write a protocol yourself'.
So here's my question: is there any library, ready protocol for client-server communication in Python (preferably 2.7)?
twisted is a very common one:
http://twistedmatrix.com/trac/
http://twistedmatrix.com/documents/13.0.0/core/examples/
If you use sockets, you can use ssh and then do scp (secured copies). If you are moving files back and forth, that would probably be the easiest way.
Maybe zeromq is something for you! There are also python bindings available. And good examples for implementing a Publisher-Subscriber pattern are also well documented.
is there any library, ready protocol for client-server communication
Generally speaking, yes: sockets (which you already found), twisted (as pointed in another answer) etc.
I wanted to send some files using Python
Use ftp! You can start an FTP server using pyftpdlib and use ftplib as client.
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 2 years ago.
Improve this question
Just wondering if there is a Python MTA. I took a look at smtpd but they all look like forwarders without any functionality.
Yes, Twisted includes a framework for building SMTP servers. There's a simple Twisted-based email server available here (also see here for some information about its development).
If you want something closer to a mail application server, there's Lamson.
If you're looking for a full MTA solution you should check out http://slimta.org/ or as previously mentioned here http://lamsonproject.org
I myself has experimented a bit with slimta and it seems to work well.
It's pretty new, so nothing like the maturity of Twisted's SMTP, but there's also Lamson.
Blackhole is an MTA (message transfer agent) that (figuratively) pipes all mail to /dev/null, built on top of asyncio and utilises async def and await statements available in Python 3.5.
While Blackhole is an MTA, none of the actions performed via SMTP or SMTPS are actually processed, and no email is delivered. You can tell Blackhole how to handle mail that it receives. It can accept all of it, bounce it all, or randomly do either of those two actions.
Think of Blackhole sort of like a honeypot in terms of how it handles mail, but it’s specifically designed with testing in mind.
Documentation
You can find the latest documentation here.
Changelog
You can find a list of changes on the blackhole website. https://kura.github.io/blackhole/changelog.html