title: Communication between python client and java server
body: <p>My aim is to send a message from python socket to java socket. I did look out on the resource mentioned above. However I am struggling to make the Python client talk to Java server. Mostly because (End of line) in python is different from that in java.</p>
  
  <p>say i write from python client: message 1: abcd message 2: efgh message 3: q (to quit)</p>
  
  <p>At java server: i receive message 1:abcdefghq followed by exception because the python client had closed the socket from its end.</p>
  
  <p>Could anybody please suggest a solution for a consistent talk between java and python.</p>
  
  <p>Reference I used: <a href="http://www.prasannatech.net/2008/07/socket-programming-tutorial.html" rel="noreferrer">http://www.prasannatech.net/2008/07/socket-programming-tutorial.html</a></p>
  
  <p><strong>Update</strong>: I forgot to add, I am working on TCP.</p>
  
  <p>My JAVA code goes like this:(server socket)</p>
  
  <pre><code>String fromclient;
  
  ServerSocket Server = new ServerSocket (5000);
  
  System.out.println ("TCPServer Waiting for client on port 5000");
  
  while(true) 
  {
      Socket connected = Server.accept();
      System.out.println( " THE CLIENT"+" "+ connected.getInetAddress() +":"+connected.getPort()+" IS CONNECTED ");
  
      BufferedReader inFromClient = new BufferedReader(new InputStreamReader (connected.getInputStream()));
  
      while ( true )
      {
          fromclient = inFromClient.readLine();
  
          if ( fromclient.equals("q") || fromclient.equals("Q") )
          {
              connected.close();
              break;
          }
          else
          {
              System.out.println( "RECIEVED:" + fromclient );
          } 
      }
  }
  </code></pre>
  
  <p>My PYTHON code : (Client Socket)</p>
  
  <pre><code>client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  client_socket.connect(("localhost", 5000))
  
  while 1:
  
      data = raw_input ( "SEND( TYPE q or Q to Quit):" )
      if (data &lt;&gt; 'Q' and data &lt;&gt; 'q'):
          client_socket.send(data)
      else:
          client_socket.send(data)
          client_socket.close()
          break;
  </code></pre>
  
  <p>OUTPUT::</p>
  
  <p>ON PYTHON CONSOLE(Client):</p>
  
  <p>SEND( TYPE q or Q to Quit):abcd ( pressing ENTER)</p>
  
  <p>SEND( TYPE q or Q to Quit):efgh ( pressing ENTER)</p>
  
  <p>SEND( TYPE q or Q to Quit):q ( pressing ENTER)</p>
  
  <p>ON JAVA CONSOLE(Server):</p>
  
  <p>TCPServer Waiting for client on port 5000</p>
  
  <p>THE CLIENT /127.0.0.1:1335 IS CONNECTED </p>
  
  <p>RECIEVED:abcdefghq</p>