os.popen vs os.system

rbt rbt at athop1.ath.vt.edu
Tue May 17 14:33:04 EDT 2005


Peter Hansen wrote:
  > You can't be doing exactly that, since there are no sockets involved...
> do you mean the above call is executed -- on the receiving end -- after 
> some signal is received via a socket in another part of the code? That's 
> not going to have any effect on things...
> 

Here's the client portion:

import socket
import time

# Prompt user for host IP and port number.
host = raw_input("What IP: ")
port = raw_input("What port: ")

# Strip any whitespace and make sure port is an int.
host = str.strip(host)
port = str.strip(port)
port = int(port)

def msg():
    msg = raw_input("Enter command to send to the server: ")
    msg = str.strip(msg)
    print "\nYou sent:", msg
    return msg

def send(msg):
    ## Send the data to the server.
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.connect((host, port))
    s.send(msg)
    s.close()

send(msg())



More information about the Python-list mailing list