Python Forum

Full Version: Help with a CLIENT command
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello,first of all I want to say that I am very new to python and don't know much.Also English is not my native/mother tongue,but I will try my best to type as clearly as I can.
I need help with the following code and how to make my IF statement execute that command if the message recieved is "python"
import socket
import sys
import time

s = socket.socket()
host = input(str("Enter Server Hostname : "))
port = 27312
s.connect((host,port))
print(" Connected to chat server")
while 1:
            incoming_message = s.recv(1024)
            incoming_message = incoming_message.decode()
            print(" Server : ", incoming_message)
			if incoming_message = "python":
			python -m webbrowser -t "http://www.python.org"
			return
            print("")
            message = input(str(">> "))
            message = message.encode()
            s.send(message)
            print("message has been sent...")
            print("")
try:
incoming_message = incoming_message.decode().strip()
this may not be necessary, but ofter is it will strip off any line feeds or white space that may interfere with comparison.
then indent line 15 and 16
fyi: please use 4 spaces for indent, code will work fine without, but it's PEP8 compliant