?
Solved

2 Indy TCPServer Instances: I need to forward data from one to the other

Posted on 2003-03-05
10
Medium Priority
?
313 Views
Last Modified: 2010-04-04
-Using Delphi 7-
Level: Novice

2 TCPServer Instances in one app. Two different computers will be connected to each TCPServer.
The big picture is I want to forward all commands/data from one client to the other. Unfortunately these components work on command/response (OnExecute event). How would I just pass the client commands between TCPServer instances. The response is givin by another application, so I need this to be a two way dumb 'tunnel'. ANY input would be greatly appreciated.
0
Comment
Question by:Jebtrix
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 5
10 Comments
 

Expert Comment

by:JimMcKeeth
ID: 8085113
Would the TIdMappedPortTCP or TIdTunnelMaster & TIdTunnelSlave combo be what you are looking for?  

Is there going to be more then one connection to each server?  If so then set the MaxConnections to 1 and you can use some code like this:

var
  FConnection1: TidTCPServerConnection;
  FConnection2: TidTCPServerConnection;

procedure TForm1.IdTCPServer1Connect(AThread: TIdPeerThread);
begin
  FConnection1 := AThread.Connection;
end;

procedure TForm1.IdTCPServer1Execute(AThread: TIdPeerThread);
var
  s: String;
begin
  s := AThread.Connection.ReadLn;
  FConnection2.writeln(s);
end;

procedure TForm1.IdTCPServer1Disconnect(AThread: TIdPeerThread);
begin
  FConnection1 := nil;
end;

For each TCPServer.  Notice that the Execute for 1 writes to the connection #2.

That is untested, but if you have trouble, and this is in fact what you are looking for just let me know.
0
 
LVL 2

Author Comment

by:Jebtrix
ID: 8086159
Works like a charm. However multi client support is something I also need. I need all multiple clients commands to be forwarded down the other 1 TCPServer connection. Because of this I'll have to add some kind of identifier to each client commands so I can parse it out and respond accordingly.

On the other side of this I have another app with a TCPClient. This connects to the TCPServer on the previous app. It will receieve all forwarded client commands. When it sees a new client cmd identifier, I need it to dynamically create a new TCPClient instance, which connects to a 3rd (local)commercial server.

Basically its a server app that funnels client sessions to another connected app, which in turn spawns appropriate client sessions and forwards to a 3rd (local) commercial app.

Thanx for your time :)
0
 

Expert Comment

by:JimMcKeeth
ID: 8089312
Would you like a code example of keeping track of the two connections and keeping them linked together?
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 2

Author Comment

by:Jebtrix
ID: 8090675
Yes please. :)
0
 

Expert Comment

by:JimMcKeeth
ID: 8090966
Just so I understand exactly what you want before I write the code:

There are two server sockets, the 1st socket will have only one connection.  The 2nd socket will have many connections and anything that comes in those connections will be sent back down the 1st socket.  And anything received on the 2nd socket will be broadcast to all the connections on the first socket?

How do you want it to behave if a connection comes in on the second socket and there is no connection on the first socket?  Should the second socket only start listening when the first socket has a connection and then stop if the first socket ever looses it's connection?  
0
 
LVL 2

Author Comment

by:Jebtrix
ID: 8091630
Q:
..anything received on the 2nd socket will be broadcast to all the connections on the first socket?

A:
Not all the connections on the first socket. An identifier tag will need to be added so on my client app it can parse each clients' commands and forward to appropriate invoked instance. This also works in reverse, the 1st server socket must parse responses and forward to appropriate client sockets.

I made a diagram that should clarify my intentions:

http://users.rcn.com/nemizis/AppDiagram.jpg

-Thanx
0
 
LVL 2

Author Comment

by:Jebtrix
ID: 8091656
Almost forgot, yes the 2nd socket will only listen when the 1st socket is connected. And for now yes if connection is lost 2nd socket will disconnect all clients. I will add some client cmd caching and some kind of 1st socket connection recover scheme later.
0
 

Expert Comment

by:JimMcKeeth
ID: 8093041
Ok, I think I have something that will work for you.  It is an object that keeps a list of TIdTCPServerConnection and string identifiers.  Just add them to the list object and then you can get the matching one later.  You can add just one (like if you only have a connection and no identifier yet (like on the OnConnect event).  So then you later call the Update method and it will sync those up.  It is pretty simple I hope.  No comments, those cost extra ;-) but if you have questions feel free to ask.

0
 

Accepted Solution

by:
JimMcKeeth earned 1000 total points
ID: 8093044
0
 
LVL 2

Author Comment

by:Jebtrix
ID: 8103030
Very nice work thank you. :) Only thing left is to figure out why disconnect method sometimes locks the application, and delphi for that matter; disconnectsocket works fine though.
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question