# Photon tcp client/ client.connect() error

**URL:** <https://community.particle.io/t/photon-tcp-client-client-connect-error/24143>\
**Category:** General\
**Created:** [July 5, 2016, 3:20pm UTC](https://community.particle.io/t/photon-tcp-client-client-connect-error/24143 "2016-07-05T15:20:53Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![pesma](https://avatars.discourse-cdn.com/v4/letter/p/d07c76/32.png) [@pesma](https://community.particle.io/u/pesma)\
**Post date:** [July 5, 2016, 3:20pm UTC](https://community.particle.io/t/photon-tcp-client-client-connect-error/24143/1 "2016-07-05T15:20:53Z")

</div>

I am trying to make a client in my photon to communicate to a server I have made in labview. The server works fine, but the client can’t connect to it. Here is my code:

```auto
TCPClient client;
byte server[] = {130,64,148,78};

void setup() {
    Serial.begin(9600);
    while(!Serial.available()) Particle.process();

    Serial.println("connecting...");

   if(client.connect(server,5002)){
        Serial.println("connected");
        client.write("testing\r\n");
        
    } else{
        Serial.println("connection failed");
    }
}

void loop() {
    if(client.available()){
       client.write("a\r\n");
    }
    if(!client.connected()){
        Serial.println();
        Serial.println("disconecting");
    }
}

```

---

<div class="post-metadata">

**Author:** ![peekay123](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/peekay123/32/810_2.png) [@peekay123](https://community.particle.io/u/peekay123)\
**Post date:** [July 5, 2016, 3:27pm UTC](https://community.particle.io/t/photon-tcp-client-client-connect-error/24143/2 "2016-07-05T15:27:42Z")

</div>

> [@pesma](#):
>
> if(client.available()){  
> client.write("a\r\n");  
> }

The check for `client.available()` indicates data from the server is ready to be read. Instead of reading (and emptying the receive buffer), you do a `client.write()`. This loop will eventually break I suspect. What output are you getting from your debug messages?

---

<div class="post-metadata">

**Author:** ![pesma](https://avatars.discourse-cdn.com/v4/letter/p/d07c76/32.png) [@pesma](https://community.particle.io/u/pesma)\
**Post date:** [July 5, 2016, 3:46pm UTC](https://community.particle.io/t/photon-tcp-client-client-connect-error/24143/3 "2016-07-05T15:46:54Z")

</div>

There are no debug messages. The problem is that it doesn’t connect to the server in the first place, the setup function.

---

<div class="post-metadata">

**Author:** ![peekay123](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/peekay123/32/810_2.png) [@peekay123](https://community.particle.io/u/peekay123)\
**Post date:** [July 5, 2016, 3:49pm UTC](https://community.particle.io/t/photon-tcp-client-client-connect-error/24143/4 "2016-07-05T15:49:18Z")

</div>

@pesma, in the least you should be seeing “connecting…” and possibly “connection failed” in your serial console. Do you get these?

---

<div class="post-metadata">

**Author:** ![pesma](https://avatars.discourse-cdn.com/v4/letter/p/d07c76/32.png) [@pesma](https://community.particle.io/u/pesma)\
**Post date:** [July 5, 2016, 3:50pm UTC](https://community.particle.io/t/photon-tcp-client-client-connect-error/24143/5 "2016-07-05T15:50:31Z")

</div>

Yes, thats exactly what I’m getting.

---

<div class="post-metadata">

**Author:** ![peekay123](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/peekay123/32/810_2.png) [@peekay123](https://community.particle.io/u/peekay123)\
**Post date:** [July 5, 2016, 4:41pm UTC](https://community.particle.io/t/photon-tcp-client-client-connect-error/24143/6 "2016-07-05T16:41:58Z")

</div>

@pesma, have you verified that port 5002 is open in any router or firewall between the photon and the target server?

---

<div class="post-metadata">

**Author:** ![pesma](https://avatars.discourse-cdn.com/v4/letter/p/d07c76/32.png) [@pesma](https://community.particle.io/u/pesma)\
**Post date:** [July 5, 2016, 5:37pm UTC](https://community.particle.io/t/photon-tcp-client-client-connect-error/24143/7 "2016-07-05T17:37:02Z")

</div>

yep, they re both using the same port.
