Network Socket exec socket.recv()?

I can get my server socket to tell my client socket to print(“yay”) by having my client socket exec an incoming string. But for some reason, when I tell my socket to assign a new variable and then print it, it tells me that my variable isn’t defined.
here’s my code:

def Input():
    InData = s.recv(1024) #test = 1
    exec InData

while True:

I actually got it working by turning it from a function to a while statement in case anyone else comes across this.