# thread and socket

**URL:** <https://forums.digi.com/t/thread-and-socket/3783>\
**Category:** NET+OS\
**Tags:** socket, thread\
**Created:** [July 17, 2007, 2:34pm UTC](https://forums.digi.com/t/thread-and-socket/3783 "2007-07-17T14:34:59Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![fana](https://avatars.discourse-cdn.com/v4/letter/f/df788c/32.png) [@fana](https://forums.digi.com/u/fana)\
**Post date:** [July 17, 2007, 2:34pm UTC](https://forums.digi.com/t/thread-and-socket/3783/1 "2007-07-17T14:34:59Z")

</div>

Hi all!  
I have a probleme with connect-me -c devellopement kit:  
I have write a function for accept a socket connect.  
When i test it, in the “applicationStart” no probleme the connection work.  
after i have creted a thread for this fonction. i enter into the thread , in the fonction and when i arrive in accept … nothing. they dont see anything…

my fonction for accept:

void servertcp(void)  
{  
int sockfd, new\_fd; /\* Écouter sur sock\_fd, nouvelle connection sur new\_fd _/  
struct sockaddr\_in my\_addr; /_ Informations d’adresse _/  
struct sockaddr\_in their\_addr; /_ Informations d’adresse du client \*/  
int sin\_size;  
int erreur;

```
    sockfd = socket(AF_INET, SOCK_STREAM, 0); /* Contrôle d'erreur! */

    my_addr.sin_family = AF_INET; /* host byte order */
    my_addr.sin_port = htons(2222); /* short, network byte order */
    my_addr.sin_addr.s_addr = inet_addr("192.168.0.163"); /* auto-remplissage avec mon IP */
    bzero(&amp;(my_addr.sin_zero), 8); /* zero pour le reste de struct */
	
	sin_size = sizeof(struct sockaddr_in);
    /* ne pas oublier les contrôles d'erreur pour ces appels: */
    erreur = bind(sockfd, (struct sockaddr *)&amp;my_addr, sizeof(struct sockaddr));

```

erreur = listen(sockfd, 3);  
new\_fd = accept(sockfd, &their\_addr, &sin\_size);  
if(new\_fd \>=0)  
{  
//traite la connection   
}   
tx\_thread\_sleep(2);  
new\_fd ++;  
}

the thread:  
int APP\_SERL\_STACK = 255;  
int reussi,state;

```
stackserver=malloc(APP_SERL_STACK);
reussi = tx_thread_create 
	(&amp;Threadserver, /* control block for root thread*/
    "server Thread", /* thread name*/
    servertcp, /* entry function*/
    NULL, /* parameter*/
    stackserver, /* start of stack*/
    APP_SERL_STACK, /* size of stack*/
    16, /* priority*/
    16, /* preemption threshold */
    1, /* time slice threshold*/
    TX_AUTO_START); /* start immediately*/

```

state = Threadserver.tx\_state;  
state = Threadserver.tx\_thread\_id;  
return reussi;   
}

thank
