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

Down

Socket & Thread, I can not understand what the problem is Find similar branches


neodiX   (2002-10-04 11:44) [0]

There is ServerSocket, type = threadblocking, I take a standard example from the help, see below:
procedure TMyServerThread.ClientExecute; var Stream: TWinSocketStream; Buffer: array [0 .. 9] of Char; begin while (not Terminated) and ClientSocket.Connected do begin try Stream: = TWinSocketStream.Create (ClientSocket, 60000); try FillChar (Buffer, 10, 0); if Stream.WaitForData (60000) then begin if Stream.Read (Buffer, 10) = 0 then ClientSocket.Close; if buffer = "stop" then clientsocket.Close; //it is mine end else ClientSocket.Close; finally Stream.Free; end; except HandleException; end; end; end;
I am waiting for a command from the client (ClientSocket1 type = nonblicking). The client sends a "stop", as soon as the server receives this command, it must break the connection with the client. Everything seems to be simple ... but after disconnecting, it throws an error, first "EAccessViolation in address ....", and then always "EOSError, SystemError, code: 5 Access is denied!"
So, why is EAccessViolation, what am I not releasing, or where am I going wrong?
and why Access is denied, as written in the help, the terminating stream is right after event "a OnClientDisconnect, that is, as I understand it, I do not need to kill it.
If anyone knows what the problem is, help, at least links to this topic!



Digitman   (2002-10-04 12:03) [1]

>> but after breaking the connection, the error is thrown

Who is throwing something? Client ? Server?



neodiX   (2002-10-04 12:06) [2]

Server



neodiX   (2002-10-04 12:18) [3]

The stream is described as follows:
TMyServerThread = class (TServerClientThread)
procedure clientexecute; override;
end;
.
var fred: TMyServerThread

In event "e OnGetThread I write:
fred: = TMyServerThread.create (false, Clientsocket)






Digitman   (2002-10-04 12:24) [4]

1. What events and how exactly do you process on the server side (except GetThread and GetSocket)?

2. If the client does not send anything to the server, but simply immediately executes Socket.Close on its side, is the same situation? Or is everything correct?



neodiX   (2002-10-04 12:48) [5]

1. None (I’m not even using GetSocket ... (if I need to handle onGetSocket, how?))
2. When the client does not send anything, but simply makes ClientSocket.Close, the same error occurs.



Digitman   (2002-10-04 12:57) [6]


> In event "e OnGetThread I write:
> fred: = TMyServerThread.create (false, Clientsocket)


And what is this "fred" like that?
Bring the text of the OnGetThread () handler entirely! There are no fred "s there in sight.
And there is
var SocketThread: TServerClientThread

This is what SocketThread you should assign in the handler a value equal to the address of the class instance you create TMyServerThread = class (TServerClientThread)



neodiX   (2002-10-04 13:06) [7]

fred is described in the var part before implementation. See (04.10.02 12: 18)
procedure TForm1.ServerSocket1GetThread (Sender: TObject;
ClientSocket: TServerClientWinSocket;
var SocketThread: TServerClientThread);
begin
fred: = TMyServerThread.create (false, clientsocket);
end;

so if fred is not needed since I have to override the procedure clientsocket;

> you must assign a value equal to the address in the handler
> the class instance you are creating TMyServerThread = class (TServerClientThread)

it i.e. like this:
socketthread: = tmyserverthread.Create (false, clientsocket);



neodiX   (2002-10-04 13:07) [8]

sorry, override procedure clientexecute



neodiX   (2002-10-04 13:12) [9]

2 Digitman,
That helped !!!
as I wrote above
> socketthread: = tmyserverthread.Create (false, clientsocket);
so it all worked right away.
Thank you so much for helping me figure this out! I go to torture sockets and flows further.




Digitman   (2002-10-04 13:13) [10]

yes, "this is like this":

socketthread: = tmyserverthread.Create (false, clientsocket);

and "overlapping the virtual method" is from another opera



Digitman   (2002-10-04 13:30) [11]

So to be - why understand something there?)
Black and white in the help says:

Write an OnGetThread event handler to create a specialized descendant of TServerClientThread for the connection to the client socket. Create the new thread with the CreateSuspended parameter set to False, and return it in the SocketThread parameter. OnGetThread only occurs if there are no idle threads in the cache.




neodiX   (2002-10-07 14:01) [12]


> OnGetThread only occurs if there are no idle threads in
> the cache

Yes, I noticed it, i.e. when I connect to the server part for the first time, then everything is OK, when I disconnect everything is also OK, but when I reconnect, the server works on the socket, but it doesn’t. A cho to write in ongetsocket?
if you write like this:
clientsocket: = TServerClientWinSocket.Create (socket, ????);
then as with the second parameter, can I describe it myself?
Its type is TServerWinSocket, then what should I do with this variable?



Digitman   (2002-10-07 14:17) [13]

>> what to write in ongetsocket?
>> cho then do with this change?

No <> cho. You can neither cho do not write - no one obliges you to process the OnGetSocket event at all.

Black and white is written in the help:

Write an OnGetSocket event handler to create a specialized TServerClientWinSocket object to use in the connection represented by the Socket parameter.

Return the new TServerClientWinSocket object in the ClientSocket parameter.

Apart from the ClientSocket parameter, no other parameters are required. With this parameter, you are free to pass either nil or a link to the TServerClientWinSocket inheritor instance created by yourself.



neodiX   (2002-10-07 14:25) [14]

But the fact is that when the client disconnects for the first time, then onClientDisconnect is triggered on the server, then terminate thread "a is done. When I reconnect, the server does not start ongetthread, but the client is ok, that is, onclientconnect is triggered without errors. But the server is silent, didn’t start any flow? I’m sure that somewhere I’m not adding something, but where?



neodiX   (2002-10-07 14:29) [15]

and when I transmit nil, then throws an error, such as Access violation at ###



Digitman   (2002-10-07 14:41) [16]

>> then terminate thread "a.

What is being done? You?

>> When I reconnect, the server does not start ongetthread,

This is normal.

>> and the client is ok, i.e. fired onclientconnect without errors.

Well, thank God!

>> But the server is silent, no thread started?

He (server) did not stop it (code.flow) - he simply put it in the cache on demand. When you reconnect, the condition for demanding the codestream that has already started earlier and is now ready for servicing a new connection will come.

Read the help - see TServerSocket.ThreadCacheSize

And where does OnGetSocket? This is not related to server multithreading.



neodiX   (2002-10-07 15:17) [17]

Thanks again, everything worked out.



VID   (2002-10-08 16:31) [18]

to neodiX: I sent you an email at neodiX@mail.ru, please see.



Pages: 1 whole branch

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

Top





Memory: 0.61 MB
Time: 0.04 c
14-14748
Urmas tormoz
2002-11-14 11:29
2002.12.05
What to procure


1-14571
sen
2002-11-19 14:15
2002.12.05
Running an external file


1-14684
_toltec
2002-11-26 03:54
2002.12.05
Variant array


6-14713
novice programmer
2002-10-09 16:06
2002.12.05
PROXY


1-14592
kloksus
2002-11-22 22:24
2002.12.05
e-mail





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