# Use web socket to transfer a String

**URL:** https://discourse.processing.org/t/use-web-socket-to-transfer-a-string/14642
**Category:** Libraries
**Created:** [October 13, 2019, 12:32am UTC](https://discourse.processing.org/t/use-web-socket-to-transfer-a-string/14642 "2019-10-13T00:32:48Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![zly1994411](https://avatars.discourse-cdn.com/v4/letter/z/c68b51/32.png) [@zly1994411](https://discourse.processing.org/u/zly1994411)
#### Post date: [October 13, 2019, 12:32am UTC](https://discourse.processing.org/t/use-web-socket-to-transfer-a-string/14642/1 "2019-10-13T00:32:48Z")

</div>

Hey guys, I was trying to transfer a String from Node server to processing, the data do come in but when I do the conditional check, the msg == “8” returns false? Can anyone help me with this? Is there a datatype difference between java and js?

JS Code:

```auto
input.addEventListener("keydown",(event) =>{
        if(event.which == 8){
            socket.send("8");
        }
    });

```

In Processing:

```auto
//this will be executed whenever the server send a message;
void webSocketEvent(String msg){
  println(msg); // print 8;
  println(msg == "8"); //return false!!!
  
  if(msg == "8"){
    audienceTweet = audienceTweet.substring(0,audienceTweet.length()-1);
  }else{
    audienceTweet = audienceTweet + msg;
  }
}

```

---

<div class="post-metadata">

### Author: ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)
#### Post date: [October 13, 2019, 12:40am UTC](https://discourse.processing.org/t/use-web-socket-to-transfer-a-string/14642/2 "2019-10-13T00:40:07Z")

</div>

might be that there is a different string as you think  
try  
[https://processing.org/reference/trim\_.html](https://processing.org/reference/trim_.html)  
first

* * *

also string comparison must use  
[https://processing.org/reference/String\_equals\_.html](https://processing.org/reference/String_equals_.html) not `==`

unless it is a character? then must use `== '8'`  
not `.equals("8")` or ` == "8"`

---

<div class="post-metadata">

### Author: ![zly1994411](https://avatars.discourse-cdn.com/v4/letter/z/c68b51/32.png) [@zly1994411](https://discourse.processing.org/u/zly1994411)
#### Post date: [October 13, 2019, 12:45am UTC](https://discourse.processing.org/t/use-web-socket-to-transfer-a-string/14642/3 "2019-10-13T00:45:32Z")

</div>

oops, I just figured it out, thanks; I used Js string comparison in java…
