# Simple client server interaction

**URL:** https://discourse.processing.org/t/simple-client-server-interaction/12105
**Category:** Libraries
**Created:** [June 16, 2019, 8:11pm UTC](https://discourse.processing.org/t/simple-client-server-interaction/12105 "2019-06-16T20:11:57Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![BlinkY](https://avatars.discourse-cdn.com/v4/letter/b/ecccb3/32.png) [@BlinkY](https://discourse.processing.org/u/BlinkY)
#### Post date: [June 16, 2019, 8:11pm UTC](https://discourse.processing.org/t/simple-client-server-interaction/12105/1 "2019-06-16T20:11:57Z")

</div>

Hi guys,  
making my way through the processing book and got to the client server chapter which is fantastic.  
I haven’t gone as far as Daniel has suggested by creating a pong game but close enough. I am moving a rect around the client from the server. However, my question is I have code to move the rect, but what is the best course of action for stopping the box once a key is released? As it stands, the box continues to move.  
I have tried keyReleased() to send a ‘stop’ int but clearly this is called after I release a button, meaning the rect doesn’t move :).

Thank you.

---

<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: [June 17, 2019, 1:27am UTC](https://discourse.processing.org/t/simple-client-server-interaction/12105/2 "2019-06-17T01:27:09Z")

</div>

i am not sure your question has anything to do with client server projects

for a keyboard operation you can use  
[https://processing.org/reference/keyPressed\_.html](https://processing.org/reference/keyPressed_.html)  
start move  
[https://processing.org/reference/keyReleased\_.html](https://processing.org/reference/keyReleased_.html)  
stop move  
OR  
while [https://processing.org/reference/keyPressed.html](https://processing.org/reference/keyPressed.html) move

---

<div class="post-metadata">

### Author: ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)
#### Post date: [June 18, 2019, 2:50pm UTC](https://discourse.processing.org/t/simple-client-server-interaction/12105/3 "2019-06-18T14:50:22Z")

</div>

What does your server code look like? It is unclear from your description if you are trying to add keyReleased to your client or server sketch. Client can use IO functions, server receives signals.

---

<div class="post-metadata">

### Author: ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)
#### Post date: [June 18, 2019, 11:46pm UTC](https://discourse.processing.org/t/simple-client-server-interaction/12105/4 "2019-06-18T23:46:39Z")

</div>

I did a quick exploration of this.

In the Processing examples…

Modify “SharedCanvasServer” as follows:

> int count;  
> void keyReleased()  
> {  
> count++;  
> s.write(0 + " " + 1 + " " + 2 + " " + count + “\n”);  
> println(“keyReleased Server”);  
> // text(“keyReleased”, 100, 100);  
> }

Modify “SharedCanvasClient” as follows:

> ```
> if (data[0]==0 &data[1]==1&data[2]==2)
> {
> println(data[3]);
> println("keyReleased");
> }
> else  
> line(data[0], data[1], data[2], data[3]);
> 
> ```

When you release a key it will increment count and display on console:

```auto
keyReleased Server
1
keyReleased
keyReleased Server
2
keyReleased
keyReleased Server
3
keyReleased
keyReleased Server
4
keyReleased

```

Note:  
Only one console is active so this is why “keyReleased Server” shows up on same console as client.  
You must start “server” and then “client” for this to work.  
The server draw window must be “active” to accept a keypress and release.  
The client and server examples worked for me using localhost IP of 127.0.0.1  
🙂
