Click here to Skip to main content
16,007,885 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Frustrated with conversion Pin
PJ Arends15-Nov-06 16:14
professionalPJ Arends15-Nov-06 16:14 
GeneralRe: Frustrated with conversion Pin
Christian Graus15-Nov-06 16:44
protectorChristian Graus15-Nov-06 16:44 
AnswerRe: Frustrated with conversion Pin
Raj Prathap15-Nov-06 18:51
Raj Prathap15-Nov-06 18:51 
GeneralRe: Frustrated with conversion Pin
Christian Graus15-Nov-06 19:13
protectorChristian Graus15-Nov-06 19:13 
GeneralRe: Frustrated with conversion Pin
Stick^15-Nov-06 19:44
Stick^15-Nov-06 19:44 
QuestionCreating a DLL Pin
colin_os15-Nov-06 10:38
colin_os15-Nov-06 10:38 
AnswerRe: Creating a DLL Pin
Blake Miller15-Nov-06 10:52
Blake Miller15-Nov-06 10:52 
QuestionCSocket connections Pin
jpyp15-Nov-06 8:53
jpyp15-Nov-06 8:53 
I have a client and a server. The server can accept only 2 connections. The client is written with VC++ and the server is written in C++.

Client:
<br />
// create the socket<br />
...<br />
// connect the socket to server<br />
result = mySck.Connect(ip address, port number);<br />
if (!result)<br />
{<br />
   // report error<br />
   ...<br />
}<br />
else<br />
{<br />
   // report connected<br />
   ...<br />
}<br />


Server:
<br />
#define QUEUE_SZ   0<br />
// create the socket<br />
...<br />
// bind the socket to the port<br />
...<br />
// listen to connection<br />
result = listen(svr_sck, QUEUE_SZ);<br />
// start the thread<br />
...<br />


Worker thread:
<br />
#define MAX_SCKS 2<br />
int totoal_scks = 0;<br />
<br />
while(1)<br />
{<br />
   if (total_scks < MAX_SCKS)<br />
   {<br />
      printf("Ready to accept connection");<br />
      tmpSck = accept(svr_sck, (struct sockaddr *) &stClntAddr, &sckAddrSize);<br />
      if (tmpSck == ERROR)<br />
      {<br />
         // report error<br />
         ...<br />
      }<br />
      else<br />
      {<br />
         // connected.<br />
         total_scks++;<br />
         // save the socket in an array<br />
         ...<br />
      }<br />
   }<br />
   else<br />
   {<br />
      // sleep a little<br />
      ...<br />
   }<br />
}<br />


There is more to the code but this should do for now.

After I connect 2 clients, the server no longer prints that it is ready to accept connections. This means that I am not executing the accept statement a 3rd time. This is what I am expecting.
The problem is:
However when I try to connect a 3rd client, it looks like the server still accepts the connection but I am not executing the code after the accept statement and total_scks is still 2. On the client side the Connect function returns 1 which means that the connection was successful. How can this happenned?
If QUEUE_SZ is 0, I can connect a 3rd connection but on the 4th, the Connect function returns 0. If QUEUE_SZ is 1, I can connect a 3rd and a 4th connections but on the 5th, Connect returns 0...and so on.
Anybody can help me with this?


jpyp

AnswerRe: CSocket connections Pin
Mark Salsbery15-Nov-06 10:19
Mark Salsbery15-Nov-06 10:19 
GeneralRe: CSocket connections Pin
jpyp16-Nov-06 6:05
jpyp16-Nov-06 6:05 
GeneralRe: CSocket connections Pin
Mark Salsbery16-Nov-06 7:08
Mark Salsbery16-Nov-06 7:08 
GeneralRe: CSocket connections Pin
jpyp16-Nov-06 7:30
jpyp16-Nov-06 7:30 
QuestionDetect button three press Pin
Johpoke15-Nov-06 8:33
Johpoke15-Nov-06 8:33 
QuestionRe: Detect button three press Pin
David Crow15-Nov-06 10:01
David Crow15-Nov-06 10:01 
AnswerRe: Detect button three press Pin
Johpoke16-Nov-06 5:32
Johpoke16-Nov-06 5:32 
QuestionRe: Detect button three press Pin
David Crow16-Nov-06 5:39
David Crow16-Nov-06 5:39 
GeneralRe: Detect button three press Pin
Mark Salsbery16-Nov-06 5:55
Mark Salsbery16-Nov-06 5:55 
GeneralRe: Detect button three press Pin
Johpoke16-Nov-06 7:09
Johpoke16-Nov-06 7:09 
GeneralRe: Detect button three press Pin
Mark Salsbery16-Nov-06 7:18
Mark Salsbery16-Nov-06 7:18 
GeneralRe: Detect button three press Pin
Johpoke16-Nov-06 7:23
Johpoke16-Nov-06 7:23 
GeneralRe: Detect button three press Pin
Mark Salsbery16-Nov-06 7:33
Mark Salsbery16-Nov-06 7:33 
GeneralRe: Detect button three press Pin
Johpoke16-Nov-06 8:39
Johpoke16-Nov-06 8:39 
AnswerRe: Detect button three press Pin
PJ Arends15-Nov-06 16:20
professionalPJ Arends15-Nov-06 16:20 
AnswerRe: Detect button three press Pin
Hamid_RT15-Nov-06 18:39
Hamid_RT15-Nov-06 18:39 
QuestionClosing popup dialog window. Pin
xkrja15-Nov-06 7:23
xkrja15-Nov-06 7:23 

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.