It looks like you are connecting to a HTTP server with your program. You're sending data to the HTTP server that doesn't look like a HTTP request, so the server complains about that with a "400 Bad Request" error message.
Why are you connecting to a HTTP server? A HTTP server does not work like an echo server, which seems to be what this program expects.