Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: TVideoCaptureDevice Live Stream From Client-Server-Client D10


This question is not answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 0
Md. Shariful Al...

Posts: 70
Registered: 9/9/01
TVideoCaptureDevice Live Stream From Client-Server-Client D10  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 25, 2016 1:28 PM
I have been struggling to send/receive TVideoCaptureDevice Live Stream to Client-Server-Client. I am using TIdTCPServer and TIdTCPClient. When try to receive I am getting Connection closed Gracefully. How to overcome the Connection closed gracefully?
Below is my code:
Server
======
procedure TWebSocket.videoServerExecute(AContext: TIdContext);
var
fip: string;
ms: TMemoryStream;
cmd: string;
begin
cmd := AContext.Connection.IOHandler.ReadLn(IndyTextEncoding_UTF8);
if AContext.Connection.Connected then
begin
fip := cmd;//AContext.Connection.Socket.Binding.PeerIP;
fip := Copy(fip, Pos(':', fip) + 1, Length(fip));
ms := vWebcamCollection.GetItem(vWebcamCollection.GetIndexByIP(fip)).StartedStream;
ms.Position := 0;
AContext.Connection.IOHandler.LargeStream := True;
AContext.Connection.IOHandler.ReadStream(ms);
AContext.Connection.IOHandler.WriteLn('DONE', IndyTextEncoding_UTF8);
end;
end;

procedure TWebSocket.videoReceiveServerExecute(AContext: TIdContext);
var
ms: TMemoryStream;
cmd, viewip: string;
begin
cmd := AContext.Connection.IOHandler.ReadLn;
viewip := cmd;
viewip := Copy(viewip, Pos(':', viewip) + 1, Length(viewip));
ms := vWebcamCollection.GetItem(vWebcamCollection.GetIndexByIP(viewip)).StartedStream;
ms.Position := 0;
AContext.Connection.IOHandler.LargeStream := True;
AContext.Connection.IOHandler.Write(ms, 0, True);
AContext.Connection.IOHandler.WriteLn('DONE', IndyTextEncoding_UTF8);
end;

Client
======
both timers interval is 500
//for sending stream
sendTimer.Enabled := False;
TThread.Synchronize(TThread.CurrentThread, (
procedure
var
aIp: String;
ms: TMemoryStream;
begin
aIp := getLocalIPAddress;
aIp := Format('send:%s', [aIp]);
videoClient.IOHandler.WriteLn(aIp, IndyTextEncoding_UTF8);
ms := TMemoryStream.Create;
videoClient.IOHandler.LargeStream := True;
imgVideo.Bitmap.SaveToStream(ms);
ms.Position := 0;
videoClient.IOHandler.Write(ms, 0, True);
videoClient.IOHandler.ReadLn(IndyTextEncoding_UTF8);
end));
sendTimer.Enabled := True;

//for receiving stream
receiveTimer.Enabled := False;
TThread.Synchronize(TThread.CurrentThread, (
procedure
var
strm: TMemoryStream;
begin
videoRcvClient.IOHandler.WriteLn('receive:' + fIPAddress,
IndyTextEncoding_UTF8);
strm := TMemoryStream.Create;
videoRcvClient.IOHandler.LargeStream := True;
videoRcvClient.IOHandler.ReadStream(strm);
videoRcvClient.IOHandler.ReadLn(IndyTextEncoding_UTF8);
strm.Position := 0;
imgVideo.Bitmap.LoadFromStream(strm);
strm.Free;
end));
receiveTimer.Enabled := True;

Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02