[Tutor] Ctypes and Sockets

Leo Nardo waterfallroad at gmail.com
Thu Jun 5 21:02:21 CEST 2014


Looking for a complete introduction to ctypes that I can understand.
I learn well from David Malans stuff, and the book 'how to think like
a computer scientist for python 3'. Hope that helps with my learning
style.

https://www.youtube.com/results?search_query=david+malan

http://openbookproject.net/thinkcs/python/english3e/index.html



I would also like someones input on the following code and what it
basically does. Im guessing it creates a connection between two
computers but sends no meaningful data? Is there a way i can
manipulate the following code to make it send strings or integers back
and forth?


""""""""" A simple
server""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

#!/usr/bin/python           # This is server.py file

import socket               # Import socket module

s = socket.socket()         # Create a socket object
host = socket.gethostname() # Get local machine name
port = 12345                # Reserve a port for your service.
s.bind((host, port))        # Bind to the port

s.listen(5)                 # Now wait for client connection.
while True:
   c, addr = s.accept()     # Establish connection with client.
   print 'Got connection from', addr
   c.send('Thank you for connecting')
   c.close()                # Close the connection


""""""""" A simple
client""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""



#!/usr/bin/python           # This is client.py file

import socket               # Import socket module

s = socket.socket()         # Create a socket object
host = socket.gethostname() # Get local machine name
port = 12345                # Reserve a port for your service.

s.connect((host, port))
print s.recv(1024)
s.close                     # Close the socket when done


More information about the Tutor mailing list