Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help with a CLIENT command
#1
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("")
Reply
#2
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
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020