Simple chat server in Python

November 24, 2017 Leave a comment

Add the following code to server.py and run.

# server.py
#!/usr/bin/python

import socket

sock = socket.socket()
host = 'localhost' # Change this to "" to receive connections from any host
port = 12221  # Any unreserved port but must be same as client
sock.bind((host, port))

sock.listen(5)
conn = None

while True:
   if conn is None:
       # Halts
       print ('[Waiting for connection...]')
       conn, addr = sock.accept()
       print('Got connection from', addr)
   else:
       # Halts
       print ( '[Waiting for response...]')
       print (conn.recv(1024))
       msg = input("Enter something to this client: ")
       conn.send(msg.encode('UTF-8'))

Add the following code to client.py.

# client.py
#!/usr/bin/python

import socket

sock = socket.socket()
host = 'localhost' # Change this to remote ip as necessary
port = 12221 # Any unreserved port but must be same as server

sock.connect((host, port))
print ('Connected to', host)

while True:
msg = input("Enter something for the server: ")
sock.send(msg.encode('UTF-8'))
# Halts
print ('[Waiting for response...]')
print (sock.recv(1024))
Advertisements

Tim Berners-Lee on the future of the web: ‘The system is failing’

November 16, 2017 Leave a comment

Tim Berners-Lee on the future of the web: ‘The system is failing’

https://www.theguardian.com/technology/2017/nov/15/tim-berners-lee-world-wide-web-net-neutrality?CMP=Share_AndroidApp_WordPress

Nice Tkinter Tutorial

November 14, 2017 Leave a comment

Swift action needed to set framework for AI and machine learning

November 11, 2017 Leave a comment

Code is STUFF

November 9, 2017 Leave a comment

In English we distinguish between count nouns and non-count or mass nouns. Consider what feels wrong about these sentences:

  • My glass is full of waters.
  • I’ve got sands in my shoes.
  • Could I borrow a money?
  • I want to buy a furniture.

The reason these are wrong is that water, sand, money and furniture are examples of mass nouns. They are STUFF. You cannot pluralize stuff and you cannot refer to “a stuff”.

Why am I telling you this? Because “code”, as in lines of computer code, is also a mass noun. Code is STUFF. You cannot refer to “codes” and you cannot write “a code”.

Please try to remember this!

Course Information for All Courses 2017-2018

August 15, 2017 Leave a comment

Google to radically change homepage for first time since 1996

July 21, 2017 Leave a comment