title: C# client Python server : Connection refused
body: <p>I'm working on a basic socket communication between C# (client) and Python (server), and I don't understand the reason why I've this error from the client:</p>
  
  <p>[ERROR] FATAL UNHANDLED EXCEPTION: System.Net.Sockets.SocketException: Connection refused
    at System.Net.Sockets.Socket.Connect (System.Net.EndPoint remoteEP) [0x00159] in /private/tmp/monobuild/build/BUILD/mono-2.10.9/mcs/class/System/System.Net.Sockets/Socket_2_1.cs:1262 
    at System.Net.Sockets.TcpClient.Connect (System.Net.IPEndPoint remote_end_point) [0x00000] in /private/tmp/monobuild/build/BUILD/mono-2.10.9/mcs/class/System/System.Net.Sockets/TcpClient.cs:284 
    at System.Net.Sockets.TcpClient.Connect (System.Net.IPAddress[] ipAddresses, Int32 port) [0x000b3] in /private/tmp/monobuild/build/BUILD/mono-2.10.9/mcs/class/System/System.Net.Sockets/TcpClient.cs:355 </p>
  
  <p>My programs are really short and easy so I suppose it's a noob question, but I just don't get it. All I want is a Client sending a message to  the server which will print it on the console. </p>
  
  <p>Here is the C# client (the error comes from :socket.Connect("localhost",9999);)</p>
  
  <pre><code>using System;
  using System.Net.Sockets;
  
  namespace MyClient
   {
  class Client_Socket{
      public void Publish(){
  TcpClient socket = new TcpClient();
  socket.Connect("localhost",9999);
  NetworkStream network = socket.GetStream();
  System.IO.StreamWriter streamWriter= new System.IO.StreamWriter(network); 
  streamWriter.WriteLine("MESSAGER HARGONIEN");
  streamWriter.Flush();   
  network.Close();
     }
  
  }
  }
  </code></pre>
  
  <p>And the Python Server:</p>
  
  <pre><code>from socket import *
  
  if __name__ == "__main__":
      while(1):
          PySocket = socket (AF_INET,SOCK_DGRAM)
          PySocket.bind (('localhost',9999))
          Donnee, Client = PySocket.recvfrom (1024)
          print(Donnee)
  </code></pre>
  
  <p>Thx for your help.</p>