Skip to content

Instantly share code, notes, and snippets.

@damianmoore
damianmoore / tcp_client.py
Created January 23, 2019 07:21
Python TCP client
# https://www.techbeamers.com/python-tutorial-write-tcp-server/
import socket
host_ip, server_port = "127.0.0.1", 9999
data = "Hello how are you?\n"
# Initialize a TCP client socket using SOCK_STREAM
tcp_client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
@damianmoore
damianmoore / tcp_server.py
Created January 23, 2019 07:19
Python TCP server
# https://www.techbeamers.com/python-tutorial-write-tcp-server/
import socketserver
class Handler_TCPServer(socketserver.BaseRequestHandler):
def handle(self):
# self.request - TCP socket connected to the client
self.data = self.request.recv(1024).strip()
print("{} sent:".format(self.client_address[0]))
@damianmoore
damianmoore / gist:7361670
Last active December 27, 2015 17:19
Syllables
VOWELS = ['a', 'e', 'i', 'o', 'u',]
def syllables(word):
''' Really basic syllable counter '''
num = 0
previously_vowel = False
for char in word:
if char in VOWELS:
if not previously_vowel: