DEBIAN PRO

DEBIAN PRO
DEBIAN

martes, 28 de julio de 2015

Python de nuevo.


Esta semana estaré preparando unos scripts en Python.

apt-get install ipython-qtconsole
apt-get install python-matplotlib
apt-get install python-numpy python-scipy python-matplotlib ipython ipython-notebook python-pandas python-sympy python-nose

PARA EJECUTAR UNA INTERFAZ QT buena y bonita
ipython qtconsole --matplotlib --pylab


Para instalar complementos a Python.
Buscar en ese sitio el paquete, descargarlo
https://pypi.python.org/simple/
Y luego
pip install xxxx.tar.gz



Y ahora me falta instalar pythonlib

DOCS oficiales de la version 2.7.9
https://docs.python.org/2.7/tutorial/index.html

Estoy leyendo el Doc
"Introduction to Python for Econometrics, Statistics and Data Analysis"


Programación de Sockets en Python

http://woozle.org/~neale/papers/sockets.html
http://pymotw.com/2/socket/tcp.html#
https://wiki.python.org/moin/TcpCommunication
https://docs.python.org/3/howto/sockets.html
http://zetcode.com/lang/python/strings/


Algunos gráficos de ejemplo
http://stanford.edu/~mwaskom/software/seaborn/tutorial/distributions.html


python server.py
SERVER 10.000 sending message
#!/usr/bin/env python
import socket
import sys

# Create a TCP/IP socket
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

# Bind the socket to the address given on the command line
server_address = ('', 10000)
sock.bind(server_address)
print >>sys.stderr, 'starting up on %s port %s' % sock.getsockname()
sock.listen(1)

while True:
print >>sys.stderr, 'waiting for a connection'
connection, client_address = sock.accept()
try:http://stanford.edu/~mwaskom/software/seaborn/tutorial/distributions.html
print >>sys.stderr, 'client connected:', client_address
while True:
data = connection.recv(16)
print >>sys.stderr, 'received "%s"' % data
if data:
connection.sendall(data)
else:
break
finally:
connection.close()



python client.py o simplemente ./client.py
CLIENT CONNECT TO 10.000
#!/usr/bin/env python
import socket
import sys

# Create a TCP/IP socket
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

# Connect the socket to the port where the server is listening
server_address = ('localhost', 10000)
print >>sys.stderr, 'connecting to %s port %s' % server_address
sock.connect(server_address)

try:

# Send data
message = 'This is the message. It will be repeated.'
print >>sys.stderr, 'sending "%s"' % message
sock.sendall(message)

# Look for the response
amount_received = 0
amount_expected = len(message)

while amount_received < amount_expected: data = sock.recv(16) amount_received += len(data) print >>sys.stderr, 'received "%s"' % data

finally:
print >>sys.stderr, 'closing socket'
sock.close()


telnet 127.0.0.1 10001


# SERVER 3
#!/usr/bin/env python

import socket

TCP_IP = '127.0.0.1'
TCP_PORT = 10001
BUFFER_SIZE = 20 # Normally 1024, but we want fast response

A = 1

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((TCP_IP, TCP_PORT))
s.listen(1)

conn, addr = s.accept()
print 'Connection address:', addr
while A > 0:
data = conn.recv(BUFFER_SIZE)

if not data:
break

if data.strip().lower() == 'q':
A = 0
break

if data.strip().lower() == 'x':
print "Ha tipeado x"
else:
print "received data:", data

conn.send(data) # echo
conn.close()

No hay comentarios:

Publicar un comentario