Joe Evans
Joe Evans

Reputation: 26

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

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

Upvotes: 1

Views: 12766

Answers (1)

Mousa Halaseh
Mousa Halaseh

Reputation: 230

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"))

Upvotes: 2

Related Questions