analitics

Pages

Sunday, November 20, 2011

Simple socket server with python

It is a small example I created a server to see how it works with a client program made ​​in C + +.
I can not say that it really is a server that does not accept multiple connections.
The script worked stable sending manually entered text.
I not checked the stability for the large data streams.
It is also normal because as you see below is just one example.

import socket 
HOST = 'your-IP'
PORT = 5001
s= socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((HOST,PORT))
s.listen(1)
conn,addr=s.accept()
print 'Conectat la =',addr
while 1:
 data = conn.recv(1024)
 if not data : 
  break
 conn.send(data)
 print data
conn.close()
The distance between me and the server was considerable.

Tuesday, October 25, 2011

The python module : spynner

On official site we see the description of the spynner module :
Spynner is a stateful programmatic web browser module for Python with Javascript/AJAX support based upon the QtWebKit framework.
The module is esay to use. With few lines of codes you can use this module to parse ,view and use web pages.
from __future__ import division
from __future__ import unicode_literals
from __future__ import print_function
import re
import spynner
from BeautifulSoup import BeautifulSoup
import time
br = spynner.Browser()
br.create_webview()
br.show()
br.set_html_parser(BeautifulSoup)
br.load("http://www.linuxtoday.com/")
br.fill("input[name=username]", "name")
br.fill("input[name=passwd]", "pass")
#br.simulate_click("input[name=submit]",True)
#br.select("IBESNA~US")
#br.select('option[value="IBESNA~US"]')
#br.wait_page_load()
br.browse()

The result is show in the image bellow:
The source code is not complete. I make this simple example just to show us how to fill some editbox.
If you wantthen you can develop this script and make more useful.
I wait your answers with source code additions and new ways of using this python module.