Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python

Socket with python?

hello friend! i have coding this socket but i dont know where is the problem .. someone can help me?

TCP socket server ( i think thats ok)

from socket import*
serverPort = 1200
serverSocket = socket(AF_INET, SOCK_STREAM)
serverSocket.bind(("", serverPort))
serverSocket.listen(1)
print("il server è pronto a ricevere")
while 1:
    connectionSocket, addr = serverSocket.accept()
    sentence = connectionSocket.recv(1024)
    capitalizedSentence = sentence.upper()
    connectionSocket.send(capitalizedSentence)
    connectionSocket.close()

TCP socket client : when i try to start python send me the message (after i type an ip address)

NameError: name 'serverName' is not defined .+

from socket import *
servernName = "ip address "
serverPort = 1200
clientSocket = socket(AF_INET, SOCK_STREAM)
message = input("frase in minuscolo: ")
clientSocket.connect((serverName, serverPort))
clientSocket.send(sentence)
modifiedSentence = clientSocket.recv(1024)
print("dal server:{}".format(modifiefSentence))
clientSocket.close()

1 Answer

Ken Alger
STAFF
Ken Alger
Treehouse Teacher

Fabrazio;

You are defining a variable with the name servernName, and using a variable named serverName later on. Double check that the variables are named the same and post back.

Happy coding,
Ken