Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Fma

Delphi & Winsock problem.

This topic is 5847 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi Not sure if this question belongs here or in the network form but here goes • Im trying to make a server using the windows API but im having a problem in checking the servers socket for connection requests and for data arraivale, here is what im trying to do:
    

procedure CheckServerSocketState();
var
   Read_Set   : TFDSet;
   Write_Set  : TFDSet;
   Error_Set  : TFDSet;
   ServerState:integer;
   nfds       : Integer;
begin
     if ClientsConnected<MaxClients then
     begin
     (*============================================================*)
               (*============================================================*)
               FD_ZERO(Read_Set);
               FD_SET(MainServer.SocketHandel ,Read_Set );

               FD_ZERO(Write_Set);
               FD_SET(MainServer.SocketHandel,Write_Set );

               FD_ZERO(Error_Set);
               FD_SET(MainServer.SocketHandel,Error_Set );

               
               (*============================================================*)
     if select(0 , @Read_Set , @Write_Set , @Error_Set ,nil)>0 then
     begin
          if Read_Set.fd_count>0 then
          begin
               AcceptClient;
          end;
     end;
     if ServerState=-1 then
        GetErrorDescription(GetLastError);
     //else

        // MessageBox(0,'select error','',0);

     (*============================================================*)
     end;
end; 
    
that compiles ok but when I run it the server stops responding!! could some one plz help me with this. [edited by - Fma on September 12, 2002 3:55:45 PM]

Share this post


Link to post
Share on other sites
Advertisement
I'm not big on networking, but why do you have that sleep(0) in there? Is this function called in a loop? And how exactly does the server stop responding? Does the app itself lock up or just the network connections?

P.S. Shouldn't .SocketHandel be .SocketHandle ?

* Not sure if this might help, it's a VB overview of the WinSock API:
1. http://www.vbip.com/winsock-api/default.asp
2. http://www.vbip.com/winsock-api/listen-accept/listen-accept-01.asp



[edited by - Xorcist on September 12, 2002 3:27:23 PM]

Share this post


Link to post
Share on other sites
Will i removed the sleep(0) function and the problem still exist, the application stops responing and i can not move it or shut it down!!

Share this post


Link to post
Share on other sites
Are you certain the problem is in the code you listed? You might want to list a bit more for us. Try stepping through using breakpoints, F7, and F8 to determine exactly where the app locks. Though it could be as simple as having a constant loop that never calls Application.ProcessMessages inside. Try replacing Sleep(0) with Application.ProcessMessages and see what happens.

Share this post


Link to post
Share on other sites
I tried stepping through it and when it reached the line with the " if select(0 , @Read_Set , @Write_Set , @Error_Set ,nil)>0 then "it froze and i had to reset the application to close it!!

Share this post


Link to post
Share on other sites
The first thing I would check is that after calling FD_SET on each of the TFDSets that those structures actually contain the proper information. You might even want to fore-go the macro and just set .fd_count and .fd_array manually for each of them.

Second, I noticed you''re using nil as the timeout, which will put the function into blocked mode. This might be a reason why it appears to lock. As it''s waiting for something to happen, which obviously doesn''t, before returning. So it just continues to wait indefinitely.

From what I''ve read, if you have a GUI it''s best to use a non-blocked sockets. Once again I''m not big on networking so most of this has been gleamed from research on my part. Hopefully some of this info has helped.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!