networking - Server process running on Indy10 partially stops responding when OnConnect event interacts with a TTabControls Tabs from another form in Lazarus -
tried describe of problem in title, , did.
basically, i've made own little tcp server indy 10 in lazarus. accepts packets in form of bytes contain char
representing letter english alphabet. i'm reading these bytes context
s' iohandler
this:
procedure tserversideform.onexecuteserver(context: tidcontext); var io: tidiohandler; keypressed: char; begin // io := context.connection.iohandler; if not(io.inputbufferisempty) begin logform.logtoform('recieving packet ' + context.binding.ip + '(' + context.binding.peerip + ')'); keypressed := io.readchar; addkeytoappropriateclient(keypressed, context.binding.ip); end; indysleep(10); // end;
and works perfectly.
however, i've got form has ttabcontrol
in it, has tab each user connected server, there tmemo
in each tab. tabs , memos created @ runtime , function that, not throw exceptions.
here's how addtab()
function other form looks (for creating tabs , memos described above):
procedure tconnectionsform.addtab(ip: string); var newmemo: tmemo; begin connectiontabs.tabs.add(ip); currtabindx := connectiontabs.tabindex; newmemo := tmemo.create(connectionsform); newmemo.anchorside[aktop].side:=asrtop; newmemo.anchorside[aktop].control:=connectiontabs; newmemo.borderspacing.top:=2; newmemo.anchorside[akbottom].side:=asrbottom; newmemo.anchorside[akbottom].control:=connectiontabs; newmemo.borderspacing.bottom:=2; newmemo.anchorside[akleft].side:=asrleft; newmemo.anchorside[akleft].control:=connectiontabs; newmemo.borderspacing.left:=2; newmemo.anchorside[akright].side:=asrright; newmemo.anchorside[akright].control:=connectiontabs; newmemo.borderspacing.right:=2; newmemo.anchors := [aktop, akbottom, akleft, akright]; newmemo.parent := connectiontabs; newmemo.visible:=true; newmemo.lines.add(ip); setlength(connectionmessagesarr, length(connectionmessagesarr)+1); connectionmessagesarr[length(connectionmessagesarr)-1] := newmemo; showonly(currtabindx); end;
it seems working fine, i've tested multiple times on own.
but when run function onconnect
function tidtcpserver
server process seems freeze until other event, onexecute
, example, happens. when onexecute
execute, messages have been accepted process executed. example, if program freezes, , while it's frozen, try minimize 1 of forms , move other form somewhere else on screen, after program unfreezes.
here's own onconnect
function:
procedure tserversideform.onconnectserver(context: tidcontext); begin logform.logtoform(context.binding.ip + ' has connected server (' + context.binding.peerip + ')'); //connectionsform.addtab(context.binding.peerip); // boom //connectionsform.connectiontabs.tabs.add('!!'); // boom end;
as i've stated in title, kind of interaction ttabcontrol
s tabs makes program freeze. connectionsform.connectiontabs.tabs.add('!!');
makes program freeze (here, connectionstabs
ttabcontrol
variable inside form called connectionsform
).
i have no idea going on in here, appreciated.
well, yes, program thread-unsafe.
solved problem adding little sync class:
type tmysync = class(tidsync) protected procedure dosynchronize; override; public context: tidcontext; end;
and doing ttabcontrol
shenanigans in dosyncronize
overridden function.
procedure tmysync.dosynchronize; begin logform.logtoform(context.binding.ip + ' has connected server (' + context.binding.peerip + ')'); connectionsform.addtab(context.binding.peerip); end;
and onconnect
has been changed to:
procedure tserversideform.onconnectserver(context: tidcontext); var sync: tmysync; begin // sync := tmysync.create; try sync.context := context; sync.synchronize; sync.free; end; end;
p.s. did analogous ondisconnect
function.
everything seems work now.
Comments
Post a Comment