These are chat archives for IndySockets/Indy

2nd
Sep 2017
Remy Lebeau
@rlebeau
Sep 02 2017 00:01
@robert010 the other methods I mentioned work in Android. you can use them to implement thread-safe events. Or, you can use Embarcadero's TMessageManager class: Sending and Receiving Messages Using the RTL
robert010
@robert010
Sep 02 2017 00:19
I decided to use tidnotify... everything compiles.
Thank you for your help I really appreciate it.
Remy Lebeau
@rlebeau
Sep 02 2017 00:20
@robert010 TIdNotify works, but just note that it is deprecated in favor of TThread.Queue() with an anonymous procedure, especially if you need to pass any variables to the main thread.
robert010
@robert010
Sep 02 2017 00:23
oh god do you have an example
I had 10 years away from programming and I can't believe how much more complicated the world has gotten
robert010
@robert010
Sep 02 2017 00:28
Ok next question after a TCPserver connects does it store the connection where it is available for send....e.g.
something like mytcpserver.?????.iohandler.writebytes
Remy Lebeau
@rlebeau
Sep 02 2017 00:35
@robert010 The connected clients are stored in the server's Contexts list, and are passed to the server's OnConnect/OnDisconnect/OnExecute events. That is where you should be doing your I/O for each client. 99% of the time, you SHOULD NOT be writing directly to a client from outside of those events. Doing so can corrupt your communications if other threads (like the events, which are running in their own thread) also write to the same client at the same time. But, if no other threads write (for instance, a server that only pushes data and doesn't respond to client requests), then writing directly to a client from outside the events is fine if you are careful with it.
robert010
@robert010
Sep 02 2017 01:32
I have a timer event writing to the server that is enabled by the on connect and disabled by the ondisconnect,,, I am always sending the same thing so there is not a onexecute to respond to other requests... but I should probably do it that way... instead so I can add other requests??? I am still a little confused on how the onexecute stuff works.. .......more important what is the onexecute event for the server?
robert010
@robert010
Sep 02 2017 02:08
I am stuck. I have both the client and server written and I am trying to debug. My server is just supposed to send data,, the client connects and then waits for the data. I start the client , I start the server in the debugger. I hit the temporary 'connect' button on the client . The server goes to the onconnect event (I have breakpoint there) It enables my timer on the form. (will this not work?) then It repeatedly calls the server onexecute event, where I have nothing to do(??),, I never get to the break point on the timer event that was enabled... Is this just a debugger thing
procedure TForm8.IdTCPServer1Connect(AContext: TIdContext);
// this is not in the main ui thread and can't call showmessage
begin
// showmessage('connect');
connectedto:=acontext;
self.SendWaveFormTimer.Enabled:=true;
end;
robert010
@robert010
Sep 02 2017 02:13

procedure TForm8.IdTCPServer1Execute(AContext: TIdContext);
// again this in second thread

var recv:string;
begin
//I don't know what to put here I am not expecting anything right now
recv := AContext.Connection.Socket.ReadLn;

end;

procedure TForm8.SendWaveFormTimerTimer(Sender: TObject);
begin
Sendwaveform;
//which has this code
// tempbyte:=RawToBytes(WaveFormSample,sizeof(TWaveFormSample));
// form8.connectedto.Connection.IOHandler.Write(tempbyte,sizeof(TWaveFormSample));

end;

Remy Lebeau
@rlebeau
Sep 02 2017 06:15
@robert010 i saw your post on StackOverflow and have responded to it