/home/lnzliplg/public_html/sockets.zip
PK �1�\�'�� �
rpython.pynu ȯ�� #! /usr/bin/python2.7
# Remote python client.
# Execute Python commands remotely and send output back.
import sys
import string
from socket import *
PORT = 4127
BUFSIZE = 1024
def main():
if len(sys.argv) < 3:
print "usage: rpython host command"
sys.exit(2)
host = sys.argv[1]
port = PORT
i = string.find(host, ':')
if i >= 0:
port = string.atoi(port[i+1:])
host = host[:i]
command = string.join(sys.argv[2:])
s = socket(AF_INET, SOCK_STREAM)
s.connect((host, port))
s.send(command)
s.shutdown(1)
reply = ''
while 1:
data = s.recv(BUFSIZE)
if not data: break
reply = reply + data
print reply,
main()
PK �1�\�vt t READMEnu �[��� This directory contains some demonstrations of the socket module:
broadcast.py Broadcast the time to radio.py.
echosvr.py About the simplest TCP server possible.
finger.py Client for the 'finger' protocol.
ftp.py A very simple ftp client.
gopher.py A simple gopher client.
mcast.py IPv4/v6 multicast example
radio.py Receive time broadcasts from broadcast.py.
telnet.py Client for the 'telnet' protocol.
throughput.py Client and server to measure TCP throughput.
unixclient.py Unix socket example, client side
unixserver.py Unix socket example, server side
udpecho.py Client and server for the UDP echo protocol.
PK �1�\q�<�� �
finger.pycnu �[��� �
Afc @ sE d d l Z d d l Z d d l Td Z d � Z d � Z e � d S( i����N( t *iO c C st t t t � } | j | t f � | j | d � x- | j d � } | sO Pn t j j | � q6 Wt j j
� d S( Ns
i ( t sockett AF_INETt SOCK_STREAMt connectt FINGER_PORTt sendt recvt syst stdoutt writet flush( t hostt argst st buf( ( s+ /usr/lib64/python2.7/Demo/sockets/finger.pyt finger s c C s� d } d } xO | t t j � k r] t j | d d k r] | t j | d } | d } q Wt j | } | s} d g } n x^ | D]V } d | k r� t j | d � } | | d } | | } n d } t | | | � q� Wd S( Nt i t -t t @( t lenR t argvt stringt indexR ( t optionst iR
t argt atR ( ( s+ /usr/lib64/python2.7/Demo/sockets/finger.pyt main% s /
( R R R R R R ( ( ( s+ /usr/lib64/python2.7/Demo/sockets/finger.pyt <module> s
PK �1�\�j{� �
echosvr.pynu ȯ�� #! /usr/bin/python2.7
# Python implementation of an 'echo' tcp server: echo all data it receives.
#
# This is the simplest possible server, servicing a single request only.
import sys
from socket import *
# The standard echo port isn't very useful, it requires root permissions!
# ECHO_PORT = 7
ECHO_PORT = 50000 + 7
BUFSIZE = 1024
def main():
if len(sys.argv) > 1:
port = int(eval(sys.argv[1]))
else:
port = ECHO_PORT
s = socket(AF_INET, SOCK_STREAM)
s.bind(('', port))
s.listen(1)
conn, (remotehost, remoteport) = s.accept()
print 'connected by', remotehost, remoteport
while 1:
data = conn.recv(BUFSIZE)
if not data:
break
conn.send(data)
main()
PK �1�\Z6qA� � throughput.pycnu �[��� �
Afc @ s] d d l Z d d l Z d d l Td
Z d Z d � Z d � Z d � Z d � Z e � d S( i����N( t *iP� i* i c C sd t t j � d k r t � n t j d d k r<