| | |
Threads, sockets and TCP
Thread Solved |
•
•
Join Date: Apr 2008
Posts: 13
Reputation:
Solved Threads: 0
Hi. Im working on a project with a relative size and Ive run into a deadlock, I need some advice in how to proceed.
I have a server that creates multiple threads to handle its clients, but each thread must serve a client multiple times,
here is the thread handling function:
Problem is that after doing the while once I need the thread to wait for a new message to reach the socket,
but how can I do that with a persistent connection? How do I know when to get the message coming from the client? Anyone with any ideas?
I have a server that creates multiple threads to handle its clients, but each thread must serve a client multiple times,
here is the thread handling function:
C Syntax (Toggle Plain Text)
void *handle_client (void *socket){ struct message_t *message; int novoSock = *(int *) socket; while(1){ message = malloc(sizeof(struct message_t)); message = network_to_message(novoSock); if(invoke(message) == 0){ message_to_network(message, novoSock); close(novoSock); } else{ printf("invoke failure\n"); close(novoSock); } free(message); } return NULL; }
Problem is that after doing the while once I need the thread to wait for a new message to reach the socket,
but how can I do that with a persistent connection? How do I know when to get the message coming from the client? Anyone with any ideas?
message_to_network should already be a function that waits for a new message to reach the socket. I'm guessing about its implementation, but you should just need to call that function -- it will return as soon as the message arrives, or when the connection times out. Obviously, it makes no sense to close the socket.
![]() |
Similar Threads
- Windows service and threads and sockets (C#)
- Pascal (Pascal and Delphi)
- suitability of .net for tcp/ip server (ASP.NET)
Other Threads in the C Forum
- Previous Thread: RLC circuit using c programming
- Next Thread: Having problem to search a string and display some info related to string
| Thread Tools | Search this Thread |
#include * ansi array arrays asterisks binarysearch calculate centimeter changingto char character convert copyanyfile copyimagefile copypdffile creafecopyofanytypeoffileinc createprocess() database dynamic execv fflush fgets file floatingpointvalidation fork forloop function getlogicaldrivestrin givemetehcodez grade gtkwinlinux histogram homework i/o ide inches include infiniteloop input interest intmain() iso keyboard km license linked linkedlist linux list looping lowest matrix meter microsoft mysql number oddnumber open opendocumentformat openwebfoundation pdf pointer posix power probleminc process program programming pyramidusingturboccodes radix read recursion recv recvblocked research reversing scheduling segmentationfault send sequential single socket socketprogramming stack standard strchr string suggestions systemcall test threads turboc unix urboc user variable whythiscodecausesegmentationfault win32api windowsapi






