Python Forum

Full Version: My sockets are not working
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I am testing my server and client with two computers.
This is my server:
import socket
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server.bind(('localhost', 9090))
server.listen(1)
copp, adr = server.accept()
while True:
   letter = copp.recv(2000)
   print(str(letter))
   copp.send(b'asd')

this is my client:
import socket
client = socket.socket()
client.connect(('localhost', 9090))
client.send(b'Yes')
And this is my problem:
Error:
Traceback (most recent call last):   File "C:\Users\Владелец\Desktop\Yes.py", line 3, in <module>     client.connect(('localhost', 9090)) ConnectionRefusedError: [WinError 10061] The connection is not established, since target computer rejected the connection request
I briefly searched the web for related issues and found this:
https://stackoverflow.com/questions/1299...ctively-re
Usually it means firewalls blocking connections, or ports not being open.

However, you said you are testing your code with two computers. Yet both, server and client, use 'localhost' address. Your client should connect to server's address, not to its own.
The server address is localhost. 

Hello! You are receiving data in infinite while loop. I think this blocks the code to run this loop and nothing else. You can't connets with the same script to the server, because the client code is never executed.
You have to use some concurensy like threading or to write another scipt for the client