Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
My sockets are not working
#1
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
Reply
#2
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.
Reply
#3
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
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Python sockets : Client sending to the server nico31780 0 2,276 May-17-2020, 07:56 PM
Last Post: nico31780
  Sockets confusion! MuntyScruntfundle 1 2,184 Oct-16-2018, 07:18 PM
Last Post: Larz60+
  Array of Listening Sockets abarnes 1 2,583 Sep-28-2017, 07:26 PM
Last Post: abarnes
  Checking connectivity for sockets in Python pikkip 1 3,004 Apr-27-2017, 05:02 PM
Last Post: Ofnuts

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020