#### Archived

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

# Delphi & Winsock problem.

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

## 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
Write_Set  : TFDSet;
Error_Set  : TFDSet;
ServerState:integer;
nfds       : Integer;
begin
if ClientsConnected<MaxClients then
begin
(*============================================================*)
(*============================================================*)

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
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 on other sites
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 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 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 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 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.

1. 1
2. 2
3. 3
4. 4
Rutin
12
5. 5

• 26
• 11
• 9
• 9
• 11
• ### Forum Statistics

• Total Topics
633700
• Total Posts
3013429
×