View Single Post
Old Nov 17th, 2004, 9:45 PM   #1
Beegie_B
Programmer
 
Join Date: Nov 2004
Location: Windsor, Ontario, Canada
Posts: 32
Rep Power: 0 Beegie_B is on a distinguished road
Send a message via ICQ to Beegie_B Send a message via MSN to Beegie_B
I'v been working on a chatting program for a couple of hours now and all seems to be going good, I threw in some random features and so on... but what I really need is someone to review my work. The only person that I had review my work ATM was my cousin who is more of a C/C++ programmer...

I used the code from the ECHO Client/Server example on the python.org website to start me off but the rest of the code is mine.

THIS IS MY SOURCE FOR THE CLIENT:
#Message Client Program written originally by: Beegie_B
#This program and the server prorgam are both Original copies of Beegie_B's
#Simple python messaging Client/Server
#Feel free to edit but leave reference to original writer
#Thank you Python.org for your great socket examples and Echo Server Example

import socket
import en_de_crypt   # Imports Beegie_B's Encryption Module
from en_de_crypt import *

HOST = '**.**.**.**'   # The remote host
PORT = 50007       # The same port as used by the server
x = ""          # Random Variable that Stores The Message
null = " "

user = raw_input("Username:")

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((HOST, PORT))
s.send(user)
user = s.recv(1024)
while x != "<exit>":
  print
  data = s.recv(1024)
  print "%s>>>%s"% (user, data) 
  x = raw_input(">>>")
  if x[:8].lower() == "encrypt:":
    x = x[8:]
    x = encrypt(x)
    s.send(x)
  elif x[:8].lower() == "decrypt:":
    x = x[8:]
    x = decrypt(x)
    print "Decrypted Message:%s"%(x)
    s.send(null)
  else:
    s.send(x)
s.close()

and HERE IS THE SOURCE FOR THE SERVER:

#Message Server Program written originally by: Beegie_B
#This program and the client prorgam are both Original copies of Beegie_B's
#Simple python messaging Client/Server
#Feel free to edit but leave reference to original writer
#Thank you Python.org for your great socket examples and Echo Server Example
import socket
import en_de_crypt   # Imports Beegie_B's Encryption Module
from en_de_crypt import *

HOST = ''         # Symbolic name meaning the local host
PORT = 50007       # Arbitrary non-privileged port
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((HOST, PORT))
s.listen(1)
x = ""          # Random Variable that Stores The Message
null = " "

user = raw_input("Username:")
while x != "<exit>":
  conn, addr = s.accept()
  conn.send(user)
  user = conn.recv(1024)
  print 'Connected by', addr, "----", user
  while x != "<exit>":
    print
    x = raw_input(">>> ")
    if x[:8].lower() == "encrypt:":
      x = x[8:]
      x = encrypt(x)
      conn.send(x)
    elif x[:8].lower() == "decrypt:":
      x = x[8:]
      x = decrypt(x)
      print "Decrypted Message:%s"%(x)
      conn.send(null)
    else:
      conn.send(x)
    data = conn.recv(1024)
    if not data: break
    print "%s>>>%s"% (user, data)
conn.close()

AND FINALLY THE SOURCE FOR THE ENCRYPT MODUAL:

#A Simple Python Text Encrypter and Decrypter by Beegie_B
#Use With any program that needs an encryption job!

def encrypt(word):
  transTable = {
    'a': 'f',
    'b': 'd',
    'c': 'i',
    'd': 'a',
    'e': 's',
    'f': 'j',
    'g': 'c',
    'h': 'z',
    'i': 'b',
    'j': 'h',
    'k': 'w',
    'l': 'k',
    'm': 'e',
    'n': 'y',
    'o': 'v',
    'p': 'n',
    'q': 'g',
    'r': 'o',
    's': 'x',
    't': 'l',
    'u': 'r',
    'v': 'm',
    'w': 't',
    'y': 'p',
    'x': 'q',
    'z': 'u'
    }
  newWord = []
  for letter in word.lower():
    try:
      newWord.append(transTable[letter])
    except KeyError:
      newWord.append(letter)
  return ''.join(newWord)

def decrypt(word):
  transTable = {
    'a': 'd',
    'b': 'i',
    'c': 'g',
    'd': 'b',
    'e': 'm',
    'f': 'a',
    'g': 'q',
    'h': 'j',
    'i': 'c',
    'j': 'f',
    'k': 'l',
    'l': 't',
    'm': 'v',
    'n': 'p',
    'o': 'r',
    'p': 'y',
    'q': 'x',
    'r': 'u',
    's': 'e',
    't': 'w',
    'u': 'z',
    'v': 'o',
    'w': 'k',
    'x': 's',
    'y': 'n',
    'z': 'h'
    }
  newWord = []
  for letter in word.lower():
    try:
      newWord.append(transTable[letter])
    except KeyError:
      newWord.append(letter)
  return ''.join(newWord)

Does anyone have any Idea's of what I can do to improve this program?

I'v been trying to allow multipul clients to connect to the server and getting rid of the problem where you have to recive a message before sending one, but all my attempts failed... if anyone has any tips for me they would be greatly appreciated

Beeg

NOTE: Some other programs I have finished are: an IP scanner (somewhat buggy and works best in win), a Port Scanner (minor bugs and somewhat slow), and an Online Link Checker (also very buggy)
Beegie_B is offline   Reply With Quote