# This is about Java 'network' library

**URL:** <https://discourse.processing.org/t/this-is-about-java-network-library/46291>\
**Category:** Libraries\
**Created:** [April 29, 2025, 11:11am UTC](https://discourse.processing.org/t/this-is-about-java-network-library/46291 "2025-04-29T11:11:31Z")\
**Posts on this page:** 1\
**Showing post:** 14

<div class="post-metadata">

**Author:** ![jafal](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jafal/32/19112_2.png) [@jafal](https://discourse.processing.org/u/jafal)\
**Post date:** [May 6, 2025, 4:31pm UTC](https://discourse.processing.org/t/this-is-about-java-network-library/46291/14 "2025-05-06T16:31:30Z")

</div>

Simple client

```Processing
import java.net.*;
import java.io.*;

Socket socket;
PrintWriter out;
BufferedReader in;

String serverIP = "192.168.1.100"; // Change to server IP
int port = 5204;
String messageToSend = "Hello from client!";
String response = "Not connected";

void setup() {
  size(400, 200);
  textAlign(CENTER, CENTER);
  
  // Connect in a separate thread
  new Thread(new Runnable() {
    public void run() {
      try {
        socket = new Socket(serverIP, port);
        out = new PrintWriter(socket.getOutputStream(), true);
        in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
        
        out.println(messageToSend);
        response = in.readLine();
        println("Server response: " + response);
      } 
      catch (IOException e) {
        response = "Connection failed: " + e.getMessage();
        e.printStackTrace();
      }
    }
  }).start();
}

void draw() {
  background(0);
  fill(255);
  text("Client\nSent: " + messageToSend + "\nResponse: " + response, width/2, height/2);
}

void exit() {
  try {
    if (in != null) in.close();
    if (out != null) out.close();
    if (socket != null) socket.close();
  } 
  catch (IOException e) {
    e.printStackTrace();
  }
  //super.exit();
}

```

---

_[View the full topic](https://discourse.processing.org/t/this-is-about-java-network-library/46291)._
