'Missing a message from TCPClient
I am new into Python and socket programming. This is my TCPClient code.
from socket import *
serverName = 'localhost'
serverPort = 12000
clientSocket = socket(AF_INET, SOCK_STREAM)
clientSocket.connect((serverName, serverPort))
sentence = input('Input lowercase sentence :')
clientSocket.send(sentence.encode())
modifiedSentence = clientSocket.recv(1024)
print('From server', modifiedSentence.decode())
clientSocket.close()
The message that should be displayed when I run the code should be :
- Input lowercase sentence : message (example sentence)
- From server MESSAGE
But only 1. was displayed, 2. wasnt even there.
Can someone point out my mistake?
This is my TPCServer code anyway.
from socket import *
serverName = 'localhost'
serverPort = 12000
serverSocket = socket(AF_INET, SOCK_STREAM)
serverSocket.bind((serverName, serverPort))
serverSocket.listen(1)
print('The server is ready to receive.')
while True:
connectionSocket, addr = serverSocket.accept()
sentence = connectionSocket.recv(1024)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
