tags:

views:

38

answers:

2

I have an application that calls connect() in a subroutine A. This sub-routine A is called when a button A is pressed.

After connection has established, user can choose to click button B. This button B has to be programmed as a separate sub-routine. However, I need TCP connection to run sub-routine B.

After connect() is called in sub-routine A, sub-routine A is exit. The connection is closed as well during exit.

Is there any way to keep this connection after connected even sub-routine A is exit?

Many thanks!

A: 

what programming you are using? Anyway you can have the socket fd & the socket struct defined in public to make it persistent across the routines or have them as parameter of the subroutine. I would expect more code to answer more precisely.

yadab
Eryn Ng
Nah, It the scope i am talking in c.
yadab
In C, my mistake. I should look into this later. Thanks!
Eryn Ng
A: 

Actually I am using objective-C programming for iPhone. However, the content are written in C. I copied and modified the sample code from internet. I am getting quite some problem with the code written.

Then, I found sample code in Objective-C language, It solved the problem. The connection can be kept alive. The sample code is from here: http://www.devx.com/wireless/Article/43551/1954

This program connect to network automatically once application is running without having user to click any connect button. This might be just fine. Now, it is time to figure out how to add a button so that user can disconnect from the network anytime.

Eryn Ng