title: Can I make a client socket only to establish a connection using python 3.6
body: <p>I'm reading about socket module in a web learning site about python, they gave us a simple steps to use socket module like follows:</p>
  <pre><code>import socket
  
  with socket.socket() as client_socket:
  
      hostname = '127.0.0.1'
      port = 9090
  
      address = (hostname, port)
      client_socket.connect(address)
  
      data = 'Wake up, Neo'
      data = data.encode()
  
      client_socket.send(data)
      response = client_socket.recv(1024)
  
      response = response.decode()
      print(response)
  </code></pre>
  <p>when executing I got the error message:
  ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine actively refused it.</p>
  <p>when I searched about this some sites was talking about server listening and I see in most of tutorials about server socket and they use it along with client one.</p>
  <p>so Is the error message related to the fact that I'm not using a server socket and is it a must to use them both</p>
  <p>Update:</p>
  <p>after reading the answers I got, I went to the test.py file that the course instructors use to evaluate our codes and I see that they make the server socket in it , so the server is already made by them. that take me back to the Error I got why does it happen then.</p>
  <pre><code>def server(self):
          '''function - creating a server and answering clients'''
          self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
          self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
          self.sock.bind(('localhost', 9090))
          self.ready = True
          try:
              self.sock.listen(1)
              conn, addr = self.sock.accept()
              self.connected = True
              conn.settimeout(15)
              while True:
                  data = conn.recv(1024)
                  self.message.append(data.decode('utf8'))
                  if len(self.message) &gt; 1_000_000:
                      conn.send(
                          json.dumps({
                              'result': 'Too many attempts to connect!'
                          }).encode('utf8'))
                      break
                  if not data:
                      break
  </code></pre>