1

This is not a duplicate.

I have searched for literally hours to find the answer and no luck so I'm asking here.

I am currently building a chat server using python's socket module. When I run the server, after the client connects and the server says so, I receive an exception:

[WinError 10038] An operation was attempted on something that is not a socket

I have built a drastically reduced server and it works where this server does not. This has confused me as it is doing the same thing nearly line for line.

tcpServer.py

tcpClient.py

Simplified:

testServer.py

testClient.py

Joe Evans
  • 26
  • 1
  • 1
  • 6

1 Answers1

2

let me clear a couple of things out for you:

  • at server side: you create a socket, bind it, and listen for connections.
  • at client side: you create a socket and then you try to connect to the server.

The server side in your case is fine, however, at the client side you need to remove this line:

s.bind(("127.0.0.1",port))

You would generally do something like this for example:

ip = '127.0.0.1'
port = 1234
s.connect((ip, port))
s.send("hello".encode("utf-8"))
while True:
    s.send(input().encode("utf-8"))
Mousa Halaseh
  • 218
  • 1
  • 5
  • 11
  • Removed the `s.bind()` line in the client and still comes up with the same exception but thanks for that. – Joe Evans Jul 03 '18 at 15:33
  • 1
    make sure that your indentations are correct, and you are **closing the sockets properly** as that's the reason why you're getting this error, I think you're trying to use the socket after calling shutdown or something similar. hope it works for you – Mousa Halaseh Jul 03 '18 at 15:51
  • After correcting my indentations I still have this error. – Joe Evans Jul 03 '18 at 16:20