title: Socket programming - Client (linux), server (Windows)
body: <p>I'm trying to create simple socket application using sockets to send stream from linux (64x ArchLinux) to server (Windows XP). </p>
  
  <p>Code I'm using I found on the internet, just to check if it is working. What is interesting the code works perfectly if I'm using Windows XP (server) and Win 8 (client), but when client is on ArchLinux it does not work. Is there some special way to connect Windows-Linux ?</p>
  
  <p>Server.java</p>
  
  <pre><code>import java.lang.*;
  import java.io.*;
  import java.net.*;
  
  class Server_pzm {
     public static void main(String args[]) {
        String data = "Toobie ornaught toobie";
        try {
           ServerSocket srvr = new ServerSocket(1234);
           Socket skt = srvr.accept();
           System.out.print("Server has connected!\n");
           PrintWriter out = new PrintWriter(skt.getOutputStream(), true);
           System.out.print("Sending string: '" + data + "'\n");
           out.print(data);
           out.close();
           skt.close();
           srvr.close();
        }
        catch(Exception e) {
           System.out.print("Whoops! It didn't work!\n");
        }
     }
  }
  </code></pre>
  
  <p>Client.java</p>
  
  <pre><code>import java.lang.*;
  import java.io.*;
  import java.net.*;
  
  class Client {
     public static void main(String args[]) {
        try {
           Socket skt = new Socket("192.168.224.78", 1234);
           BufferedReader in = new BufferedReader(new
              InputStreamReader(skt.getInputStream()));
           System.out.print("Received string: '");
  
           // while (!in.ready()) {} line removed
           System.out.println(in.readLine());  
  
  
           System.out.print("'\n");
           in.close();
        }
        /* lines removed catch(Exception e) {
           System.out.print("Whoops! It didn't work!\n");
        } */
  
        // added exception handling
        catch(UnknownHostException e) {
           e.printStackTrace();
        }
        catch (IOException e){
           e.printStackTrace();
        }
  
     }
  }
  </code></pre>
  
  <p>EDIT</p>
  
  <p>Sorry, I did not specify what I meant by not working. I meant I got an exception which later prints System.out.print("Whoops! It didn't work!\n"); as in the catch blok. Win 8 and Arch Linux are installed on the same laptop, while the code is on my dropbox folder in both systems (so the code is the same) - I will post the actual exception, after I get back to my laptop</p>
  
  <p>EDIT 2:</p>
  
  <p>I updated code and this is exception I got:</p>
  
  <pre><code>java.net.ConnectException: Connection refused
          at java.net.PlainSocketImpl.socketConnect(Native Method)
          at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
          at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
          at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
          at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
          at java.net.Socket.connect(Socket.java:579)
          at java.net.Socket.connect(Socket.java:528)
          at java.net.Socket.&lt;init&gt;(Socket.java:425)
          at java.net.Socket.&lt;init&gt;(Socket.java:208)
  </code></pre>