[Tutor] Network Programming Information and terminology
Byron
byron at christianfreebies.com
Mon Aug 22 06:37:27 CEST 2005
Hi John,
Here is a link that you might find useful:
*http://compnetworking.about.com/od/basicnetworkingconcepts/*
---
Listed below are two very basic Python IM programs. You'll need to run
the server first -- let it run in the background. Once this is running,
start the second program, which allows you to type in a message and then
the server program will acknowledge the reception of the data and then
send a message back to you.
---
# PYTHON SERVER
import socket
# Create connection.
mySocket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
mySocket.bind(('', 2727))
while True:
# Get data coming in from client.
data, client = mySocket.recvfrom(100)
print 'We have received a datagram from', client, '.'
print data
# Send a response to confirm reception!
mySocket.sendto ( 'Message confirmed: ' + data, client )
---
# Client program
from socket import *
# Set the socket parameters
host = "127.0.0.1"
port = 2727
buf = 1024
addr = (host,port)
# Create socket
UDPSock = socket(AF_INET,SOCK_DGRAM)
def_msg = "===Enter message to send to server===";
print "\n", def_msg
# Send messages
while (1):
data = raw_input('>> ')
if not data:
break
else:
if(UDPSock.sendto(data,addr)):
print "Sending message '",data,"'....."
# Receive the response back from the server.
data, client = UDPSock.recvfrom(100)
print data
# Close socket
UDPSock.close()
---
Hope this helps,
Byron
-------------------------------------------------------------------
John Walton wrote:
>Hello. It's me again. Thanks for all the help with
>the Python Networking Resources, but does anyone know
>what I'll need to know to write a paper on Network
>Programming and Python. Like terminology and all
>that. Maybe I'll have a section on socketets, TCP,
>Clients (half of the stuff I don't even know what it
>means). So, does anyone know any good websites with
>Network Programming information. Thanks!
>
>John
>
>__________________________________________________
>Do You Yahoo!?
>Tired of spam? Yahoo! Mail has the best spam protection around
>http://mail.yahoo.com
>_______________________________________________
>Tutor maillist - Tutor at python.org
>http://mail.python.org/mailman/listinfo/tutor
>
>
>
More information about the Tutor
mailing list