Click here to Skip to main content
15,902,863 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Free Resource?? Pin
thenewbee4-Jul-07 21:34
thenewbee4-Jul-07 21:34 
QuestionRe: Free Resource?? Pin
Hamid_RT4-Jul-07 22:26
Hamid_RT4-Jul-07 22:26 
AnswerRe: Free Resource?? Pin
thenewbee5-Jul-07 1:51
thenewbee5-Jul-07 1:51 
QuestionRe: Free Resource?? Pin
David Crow5-Jul-07 2:53
David Crow5-Jul-07 2:53 
AnswerRe: Free Resource?? Pin
thenewbee5-Jul-07 19:25
thenewbee5-Jul-07 19:25 
QuestionCreating table/report using data in Oracle database Pin
__yash__4-Jul-07 19:04
professional__yash__4-Jul-07 19:04 
QuestionSocket Pin
shakumar_224-Jul-07 18:57
shakumar_224-Jul-07 18:57 
AnswerRe: Socket [modified] Pin
Nuxser4-Jul-07 19:36
Nuxser4-Jul-07 19:36 
Not very clear about your problem from your post.

Generally, for a server process you will,

1. Initialize Winsock
2. Create a socket and bind it to network interface and port. NOTE: This is the listening socket
3. Then, you can say, prepare the socket to listen for connection request in that socket
4. Then you wait on that socket for incoming connection by accept(..) call.

When this call returns, it will return a new socket where the client is connected. Note that the original listen socket is not used by the connection. You take the new socket returned by accept(..) and do you communication and finally close it. You must not close the socket on which you are listening.

So in that regards, I am not sure in your post, which socket you are closing.

(Even if you are using Unix/Linux the concept remains the same as they are POSIX sockets)

Look at the example given in the link:

http://msdn2.microsoft.com/en-us/library/ms737526.aspx

Within the example, once accept has return with a valid connected socket (a.k.a the 'else' portion of the check)
you can initiate a thread where you will use the socket to do your stuff with the client and close the socket.

You only close the socket you are listening on, when you terminate the server app or you do not wish to listen for connection on that socket any more.


-- Soyuz

-- modified at 1:45 Thursday 5th July, 2007

Wanted to add that, once accept(...) returns, and you deal with you client (either by initiating a separate thread or in the same thread) you need to go back to wait on accept(...) again to server other incoming request.


With the close & shutdown call, I remember an issue about the TCP/IP stack taking some time to actually making the socket available for further reuse and the workaround was (as far as I remember) to set socket option to socket reuse.







Questionextracting the decimal places ..... ????? Pin
Zealous_Me4-Jul-07 13:20
Zealous_Me4-Jul-07 13:20 
AnswerRe: extracting the decimal places ..... ????? Pin
David Crow5-Jul-07 2:59
David Crow5-Jul-07 2:59 
AnswerRe: extracting the decimal places ..... ????? Pin
Mark Salsbery5-Jul-07 8:48
Mark Salsbery5-Jul-07 8:48 
GeneralRe: extracting the decimal places ..... ????? Pin
G Haranadh9-Jul-07 21:23
G Haranadh9-Jul-07 21:23 
QuestionAccessing private members of a base Class Pin
ForNow4-Jul-07 12:00
ForNow4-Jul-07 12:00 
AnswerRe: Accessing private members of a base Class Pin
Christian Graus4-Jul-07 12:10
protectorChristian Graus4-Jul-07 12:10 
GeneralRe: Accessing private members of a base Class Pin
ForNow4-Jul-07 12:16
ForNow4-Jul-07 12:16 
AnswerRe: Accessing private members of a base Class Pin
Rajkumar R4-Jul-07 18:32
Rajkumar R4-Jul-07 18:32 
GeneralRe: Accessing private members of a base Class [modified] Pin
G Haranadh4-Jul-07 21:22
G Haranadh4-Jul-07 21:22 
GeneralRe: Accessing private members of a base Class Pin
David Crow5-Jul-07 3:01
David Crow5-Jul-07 3:01 
AnswerRe: Accessing private members of a base Class Pin
Rajkumar R8-Jul-07 23:19
Rajkumar R8-Jul-07 23:19 
GeneralRe: Accessing private members of a base Class Pin
ForNow5-Jul-07 6:42
ForNow5-Jul-07 6:42 
AnswerRe: Accessing private members of a base Class Pin
Joe Woodbury5-Jul-07 10:14
professionalJoe Woodbury5-Jul-07 10:14 
GeneralRe: Accessing private members of a base Class Pin
ForNow5-Jul-07 11:30
ForNow5-Jul-07 11:30 
GeneralRe: Accessing private members of a base Class Pin
Joe Woodbury5-Jul-07 12:00
professionalJoe Woodbury5-Jul-07 12:00 
GeneralRe: Accessing private members of a base Class Pin
ForNow5-Jul-07 13:22
ForNow5-Jul-07 13:22 
GeneralRe: Accessing private members of a base Class Pin
Joe Woodbury5-Jul-07 13:31
professionalJoe Woodbury5-Jul-07 13:31 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.