Home > front end >  socket programming in python - bizzare error for unknown reason
socket programming in python - bizzare error for unknown reason

Time:09-24

I am trying to communicate with a remote server located in this ip address and port: 18.198.234.32, port 6666, and after receiving the "welcome" message from the server, I can not get a further response from him, regardless of the fact that I am sending the right input and using the right syntax.

I am attaching the code I wrote. I would really appriciate if you could take a look.

**Important note - the server is working just fine - I checked it using net cat add on in chrome (since I have windows). The problem must be in the code itself.

Please assist me! Thanks in advance.

*** the code ***

import socket

my_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

my_socket.connect(("18.198.234.32", 6666))

data = ""

data = my_socket.recv(1024).decode()

print(data)
to_send = input("enter: ")

my_socket.send(to_send.encode())

data = my_socket.recv(1024).decode() #getting stuck - not receving anything.

print(data)

my_socket.close()

CodePudding user response:

Your input needs to be terminated with a newline character "\n".

input() 's return value will not include one.

my_socket.sendall((to_send   "\n").encode())
  • Related