Home
Top.Mail.Ru Yandeks.Metrika
Forum: "Networks";
Current archive: 2003.06.02;
Download: [xml.tar.bz2];

Down

People help with a socket error .... Find similar branches


TankMan   (2003-03-01 15:00) [0]

Most likely there was already such a question, but even so ... ClientSocket is running, on OnConnect, it’s worth sending a text, to Disconnect, nothing like that, just an indicator like a boolean is set to true, OnError is just zeroing the error, also a timer, with an interval ~ 1 second, which the indicator processes with OnDisconnect-a and if it is true Client.Active: = true ... in general, I think there is nothing of the sort ... there are no visible errors, it connects to the server perfectly, and it disconnects too :), but here it costs the server not to be available, for some minutes 30 ... or maybe even less, something like that flies on the client WinSock error 10055 ... and what this error means can not imagine :( can help ...
Or maybe you’ll even throw off the example, the most “correct” option of maintaining a stable (constant) connection to the server ... otherwise I really need it, the graduation thesis is on .... I won’t show it to the head for 10 minutes :) ...



Digitman   (2003-03-03 08:37) [1]

in OnError (), other than that, do:

Socket.Disconnect (Socket.SocketHandle);


and don’t have the habit of sending something on the OnConnect () event.

transmitter availability is an OnWrite () event



BorisUK   (2003-03-03 09:47) [2]

WinSock error 10055 ...
You did not look at a borland socket server?
Most likely he has the option to kill an inactive session just after this time ...
If I was right .. and you didn’t look at him, then
here after ... You will test the number of sessions, you will also be surprised ... "How can it be more than nine ..." I will answer right away ...
There is also such a parameter :)
Presets see more.



Digitman   (2003-03-03 10:32) [3]


> BorisUK


BSS has nothing to do with it



Polevi   (2003-03-03 13:47) [4]

10055 - WSAENOBUFS
Buffer space has run out



nikb   (2003-03-03 19:51) [5]

A gde mojno podrobnee prochitat o WSABASEERR + xx errors?



Digitman   (2003-03-04 08:50) [6]


> nikb


MSDN + help + http://book.itep.ru



TankMan   (2003-03-04 19:00) [7]

So all the same? Whom should I listen to? :) ... I’m not from home on the internet right now, so I’ll try Digitman’s and BorisUK’s advice later, and if that doesn’t help me? What should I do with this buffer overflow?



TankMan   (2003-03-05 03:13) [8]

>> BorisUK
And where to look at all these parameters?



Digitman   (2003-03-05 08:29) [9]


> TankMan


Understand that not TClientSocket, but TSocketConnection is used to communicate with BSS! You have specifically - TClientSocket, therefore, there can be no talk of any BSS, and, therefore, advice from <BorisUK> on this topic takes you away from the essence of the problem.

I have already given you the right decision.

see <Digitman © (03.03.03 08: 37)>



TankMan   (2003-03-16 23:51) [10]

>> Digitman
The right decision, you mean -
"in OnError (), other than that, do:
Socket.Disconnect (Socket.SocketHandle); "?
Delivered ... if the client is connected to the server, then everything is OK, but if the server is turned off, the client in this case tries to connect every 5 seconds, all the same, after 30-40 minutes the client crashes with an error "The program performed an invalid operation .... "... Why I don’t understand ... Could you give the source (example) a client and a server that would constantly keep a connection between each other ...
And can I ask you another question? So my client connected to the server, the server got another Connection, then we abruptly (reset) reboot on either side - and as a result, very often (almost always) one of the pair does not notice that the other is already disconnected, i.e. rebooted the client, and in Connections the server of these clients already has 2: (... and the same thing, the server disconnected, and the client all the same "thinks" that it is connected, and as a result, commands from the server are not accepted due to the fact that the client is not connected, and the client does not try to connect ....
Here is such a long introduction to the question ... and the question is, what is the best way to check the connection?





Digitman   (2003-03-17 08:34) [11]


> after 30-40 minutes, the client crashes with the error "The program completed
> invalid operation .... "


I think that this fatal error has nothing to do with error handling in OnError ()


> source (example) client and server, which would be constantly
> would keep the connection between themselves


there are no such sources ... neither I have anyone else ... and cannot have ... a connection exists until (with a physically existing connection) the receiver responds in time to the SYN packet of the transmitter in SYN -ACK package. This is not the physical layer, but the TCP / IP protocol layer.
see http://book.itep.ru, TCP


> one of the pair does not notice that the other is already disconnected, i.e.
> rebooted client


this is absolutely normal ... to detect such a situation, that side of the connection that is interested in the timely determination of the fact of the "gap" may:

- periodically send a certain control message; if the other party does not receive a response to this message “on time”, it is considered that the partner has “fallen off” and the connection with it is forcibly broken; at the time of sending the message, if the connection is physically disconnected, the send method will return a failure with an appropriate exception, in the handler of which the socket should be closed

- to expect, at predetermined time periods, a certain counter message from the connection partner; the absence of an input message in a given period of time is regarded as a lack of communication and the connection is forcibly broken by closing the socket

Such a "kitchen" is quite common in distributed network applications (for example, ICQ-networks) and is often called "Keep Alive" (you can roughly translate as "do you want to be alive? Take care of it yourself - stay that way, notifying the partner in time that are you still alive")



TankMan   (2003-03-17 23:34) [12]

Digitman
>> after minutes 30-40, the client crashes with the error "The program completed
>> invalid operation .... "

> I think that this fatal error has nothing to do with error handling in OnError ()
I don’t know why, but in any case this is the case if the server is turned on and the client successfully connects to it, then the client works until you turn it off, and if the server is not available, the client tries to connect to it every 10 seconds. it will connect ... in this situation, the client holds for about 30-40 minutes, as I already said, but if you put it so that it tries to connect every 5 seconds, it crashes much faster .... from this I realized that something wasn’t so it is with the socket, and most likely in OnError or onDisconnect ... if I disconnect attempts to connect to the server , None of this happens, at first I thought it was something related to the loss of resources, but I checked MemProof, nothing of the sort happens .... What then may be the catch I don’t understand? ...







статик   (2003-03-18 02:28) [13]

read everything on your fingers painted here
http://ganja.loopback.ru/view.php?id=2896



Digitman   (2003-03-18 08:22) [14]

code lead



dimich1978   (2003-03-18 11:53) [15]

A bit of that can help you (based on Digitman's advice):
For server:
procedure TForm1.ServerSocket1ClientError (Sender: TObject;
Socket: TCustomWinSocket; ErrorEvent: TErrorEvent;
var ErrorCode: Integer);
begin
case ErrorCode of
// what kind of error?
WSAECONNREFUSED:
begin
Socket.Disconnect (Socket.SocketHandle); // close the nest
ErrorCode: = 0; // reset the error
showmessage ("host unreachable or port inactive");
end;
// host is unavailable or port is inactive
WSAECONNABORTED:
begin
Socket.Disconnect (Socket.SocketHandle); // close the nest
ErrorCode: = 0; // reset the error
showmessage ("the host interrupted the previous connection on its own initiative");
end;

// the host interrupted the previous connection on its own initiative
WSAECONNRESET: // connection terminated for other reasons
begin
Socket.Disconnect (Socket.SocketHandle); // close the nest
ErrorCode: = 0; // reset the error
showmessage ("the connection was broken for other reasons");
end;
end;
end;

For the client (everything is almost the same, the difference is in the less informed user):
procedure TForm1.ClientSocket1Error (Sender: TObject;
Socket: TCustomWinSocket; ErrorEvent: TErrorEvent;
var ErrorCode: Integer);
begin
case ErrorCode of // what error?
WSAECONNREFUSED, // host is unavailable or port is inactive
WSAECONNABORTED, // the host interrupted the previous connection on its own initiative
WSAECONNRESET: // connection terminated for other reasons
begin
Socket.Disconnect (Socket.SocketHandle); // close the nest
ErrorCode: = 0; // reset the error
timer2.enabled: = true; // start the timer on the connection
end;
end;
end;



TankMan   (2003-03-24 00:50) [16]

>> dimich1978
Now I’m not on my computer on the Internet, so I can’t try the code, but now I look at your example and think that errors may occur because my timer does not depend on whether the client is connected or not, just I have a "switch" in onerror and ondisconnect and just in the same timer with an interval of about 10 seconds. it checks whether the switch is on or not, and tries to connect accordingly, ... I think it is because of this that the glitch .. i.e. even before receiving an error when trying to connect, he again tries to connect .... but in general we’ll see ....



VID   (2003-03-24 02:42) [17]

TO TankMan:
dimich1978 is right, except for one detail:

with an onClientError server, you should write:
Server.Socket.Disconnect (Socket.SocketHandle);
ErrorCode: = 0;
Note Server.Socket.Disconnect and not Socket.Disconnect - these are two different things.

Well, for fidelity, you can also finish off:
try CloseHandle ( socket.Handle); except end;
try FreeAndNil ( socket); except end;

Well, in the case of the client ...
Socket.Disconnect (Socket.SocketHandle) or Client.Socket.Disconnect ...
in this case there is no difference, because we are talking about the same socket.
Well, you should not forget about ErrorCode: = 0;

that's all.



Digitman   (2003-03-24 08:36) [18]


> dimich1978
> Vid


WSAECONNREFUSED on the server side will never occur
WSAECONNABORTED, WSAECONNRESET - errors that never occur asynchronously (neither on the server nor on the client). They occur only at the moments of calls to the transport functions of the socket and are immediately processed by the TCustomWinSocket class with an automatic call to Disconnect () (immediately before excitation of the corresponding image). So, an explicit call to Disconnect () in the OnError () handler in such situations is superfluous (if not to say dangerous), because with synchronous internal processing of such errors, forced disconnection of the connection (with the corresponding release of resources and the generation of the OnDisconnect event) is an obvious thing.



TankMan   (2003-04-02 00:30) [19]

People! Thanks earned! Everything connects normally ... and the prog ceased to crash without a server, only the problem appeared in another ... if you constantly turn the server on and off, the clients stop seeing the server point-blank after a while, only after the reboot the client becomes clear ... what can to be a problem? Once upon a time, I already heard this problem from someone else, but then I did not deal with networks and network programming ... but right now I started ... and immediately stumbled ...



Pages: 1 whole branch

Forum: "Networks";
Current archive: 2003.06.02;
Download: [xml.tar.bz2];

Top





Memory: 0.64 MB
Time: 0.041 c
6-3025
Karelin Artem
2003-03-17 16:04
2003.06.02
Incoming modem connections.


3-2765
Ximik
2003-05-13 01:03
2003.06.02
LookUp fields


14-3086
nizar
2003-05-14 04:50
2003.06.02
Forum reader


7-3193
Aleksandr
2003-04-01 11:56
2003.06.02
Is it necessary to somehow kill Mutex upon completion of work?


1-2840
Cranium
2003-05-19 21:00
2003.06.02
How TMainMenu can change the color .....





afrikaans albanian Arabic armenian azerbaijani basque belarusian bulgarian catalan Chinese (Simplified) Chinese (Traditional) croatian Czech danish Dutch English estonian filipino finnish French
galician georgian German greek haitian Creole hebrew Hindi hungarian icelandic indonesian Irish italian Japanese Korean latvian lithuanian macedonian malay maltese norwegian
persian polish portuguese Romanian russian serbian slovak Slovenian Spanish swahili Swedish thai turkish Ukrainian urdu vietnamese welsh yiddish bengali bosnian
cebuano Esperanto gujarati hausa hmong igbo javanese kannada Khmer lao latin maori marathi mongolian nepali punjabi somali tamil telugu yoruba
zulu
English French German Italian Portuguese Russian Spanish