title: TCP socket connection in react-native
body: <p>I want to make a TCP socket connection.</p>
  <p>my server code in java.</p>
  <pre><code>// File Name GreetingServer.java
  import java.net.*;
  import java.io.*;
  
  public class GreetingServer extends Thread {
  private ServerSocket serverSocket;
  
   public GreetingServer(int port) throws IOException {
    serverSocket = new ServerSocket(port);
    serverSocket.setSoTimeout(10000);
    }
  
     public void run() {
       while(true) {
        try {
          System.out.println(&quot;Waiting for client on port &quot; + 
             serverSocket.getLocalPort() + &quot;...&quot;);
          Socket server = serverSocket.accept();
          
          System.out.println(&quot;Just connected to &quot; + server.getRemoteSocketAddress());
          DataInputStream in = new DataInputStream(server.getInputStream());
          
          System.out.println(in.readUTF());
          DataOutputStream out = new DataOutputStream(server.getOutputStream());
          out.writeUTF(&quot;Thank you for connecting to &quot; + server.getLocalSocketAddress()
             + &quot;\nGoodbye!&quot;);
          server.close();
          
       } catch (SocketTimeoutException s) {
          System.out.println(&quot;Socket timed out!&quot;);
          break;
       } catch (IOException e) {
          e.printStackTrace();
          break;
       }
       }
     }
  
    public static void main(String [] args) {
       int port = Integer.parseInt(args[0]);
       try {
          Thread t = new GreetingServer(port);
          t.start();
       } catch (IOException e) {
          e.printStackTrace();
      }
    }
  }
  </code></pre>
  <p>I want to make a client in react-native .</p>
  <p><strong>Import the library:</strong></p>
  <pre><code>import TcpSocket from 'react-native-tcp-socket';
  // const net = require('react-native-tcp-socket');
  </code></pre>
  <p><strong>Client</strong></p>
  <pre><code>// Create socket
  const client = TcpSocket.createConnection(options, () =&gt; {
    // Write on the socket
   client.write('Hello server!');
  
    // Close socket
   client.destroy();
  });
  
  client.on('data', function(data) {
    console.log('message was received', data);
  });
  
  client.on('error', function(error) {
    console.log(error);
  });
  
  client.on('close', function(){
    console.log('Connection closed!');
    });
  </code></pre>
  <p>I referred to the above code <a href="https://www.npmjs.com/package/react-native-tcp-socket" rel="nofollow noreferrer">here</a>.</p>
  <p>But, I need more information.</p>
  <p>Where can I provide the server's IP address in client side?</p>
  <p>I need a small example for TCP client in react-native.</p>