Home/Support/Support Forum/thread and socket
Welcome to Digi Forum, where you can ask questions and receive answers from other members of the community.

thread and socket

0 votes
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(&(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 *)&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
(&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
asked Jul 17, 2007 in NET+OS by fana New to the Community (8 points)
recategorized Dec 18, 2013 by tuxembb

Please log in or register to answer this question.

...