# Trying to connect gprs and trying to send data using TCP but facing problem

**URL:** <https://forum.legato.io/t/trying-to-connect-gprs-and-trying-to-send-data-using-tcp-but-facing-problem/2385>\
**Category:** Legato Linux distribution (Yocto project)\
**Created:** [March 11, 2017, 10:28am UTC](https://forum.legato.io/t/trying-to-connect-gprs-and-trying-to-send-data-using-tcp-but-facing-problem/2385 "2017-03-11T10:28:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![rups](https://avatars.discourse-cdn.com/v4/letter/r/5e9695/32.png) [@rups](https://forum.legato.io/u/rups)\
**Post date:** [March 11, 2017, 10:28am UTC](https://forum.legato.io/t/trying-to-connect-gprs-and-trying-to-send-data-using-tcp-but-facing-problem/2385/1 "2017-03-11T10:28:05Z")

</div>

Hi ,

I want to connect to gprs and establish socket connection with server and then send and receive data.  
For this, I have 1st established connection using commands as below  
cm radio  
cm data  
(if apn not set) cm data apn ‘apn name’  
(if not connected ) cm data connect &

here it is showing connected using interface ‘rmnet0’  
In project, I have used again data connection functions and then added socket code for connection to server and send data.

I have used following functions:  
le\_data\_ConnectService  
le\_data\_AddConnectionStateHandler  
le\_data\_Request

after these three connection functions, I am starting socket code.  
while running application, it takes much time to create socket and execution of code.

My question is that,  
my code flow is correct or not and if I doing wrong then what is correct flow to connect and send and receive data ?

---

<div class="post-metadata">

**Author:** ![dfrey](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.legato.io/dfrey/32/563_2.png) [@dfrey](https://forum.legato.io/u/dfrey)\
**Post date:** [March 11, 2017, 7:16pm UTC](https://forum.legato.io/t/trying-to-connect-gprs-and-trying-to-send-data-using-tcp-but-facing-problem/2385/2 "2017-03-11T19:16:28Z")

</div>

I think the code flow is correct. Just to be clear, you need to wait for the connection state change handler to be called after calling `le_data_Request` and you should verify that the `isConnected` parameter is true. At that time the connection is ready for you to create the socket.

---

<div class="post-metadata">

**Author:** ![rups](https://avatars.discourse-cdn.com/v4/letter/r/5e9695/32.png) [@rups](https://forum.legato.io/u/rups)\
**Post date:** [March 14, 2017, 11:10am UTC](https://forum.legato.io/t/trying-to-connect-gprs-and-trying-to-send-data-using-tcp-but-facing-problem/2385/3 "2017-03-14T11:10:02Z")

</div>

I am connecting to gprs using terminal command (cm data connect &)first and then running my application. In this case only I am able to send and receive data , in other case socket connection does not get connect to server.  
I want to do everything through my code only. that is, gprs connection.  
How can I do this? or  
How can I give Terminal commands to mangOH board using my code?
