I’ve been playing recently with python and network programming. IMHO, writing a server that makes use of select seems to be the simplest select code I’ve ever read/wrote. Here’s how it goes:
if(len(sys.argv) != 2):
print "a port must be supplied"
sock = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
read_list = [sock]
current_data = ""
infds,outfds,errfds = select.select(read_list,,read_list,0.05)
for socket in infds:
clientsock,client_addr = sock.accept()
current_data = socket.recv(4196)
print "client disconnected"
for socket in [socket for socket in read_list if socket != sock]:
if current_data != "":
socket.send("a client wrote:%s"%current_data)
The code illustrates a VERY basic messaging “application”, that will listen on a user-supplied port. Each time a client writes a message, the server sends the message to all connected sockets. The message doesn’t get sent to server again ( notice the socket != sock ). The deal with select is that you need to supply it with a list to check for available data, this is the read_list. I’m no socket guru, but this really looks simple, right?
In the previous posts, I’ve written about the techniques one could use to perform web scraping. I feel it’s important that developers know how to detect spiders and how to restrict them.
I think that the StackOverflowquestion “How do you stop scripters from slamming your website hundreds of times a second?” compiles the best information related to this topic. You can read the whole thing here.
So, oficially, I’m not able to perform the 50 day plan from Never Gymless. That’s why I decided to throw my own:
one day with various exercises for upper/lower body
one day shadow boxing
I started the shadow boxing about a month ago, and I’m really noticing progress. I went from being able to sustain the effort 2 minutes to about 7 minutes. On the other side, the upper body training is pretty much keeping my muscles guessing, which I consider to be a good thing, as I’m sure this will help me progress quicker. Unfortunately, a upper body training session leaves my muscles sore for about 2 days. I’m sure that pretty soon this phase will dissappear.
Even though it may be too soon to be really sure about this, I am seeing great improvements with my back pain. Coding each day for several hours is pretty demanding on the back, and lately, I’ve been feeling it. The funny thing is that this back pain manifests mostly when I’m going to sleep. I am glad that for the past 3 days it hasn’t come back. I hope it stays gone 🙂
I’m sure Scala will make a nice addition in every coder’s toolkit! I challenge you to try it!