Communication between 2 Socket listener on 2 different port with one program and server.

vino via Digitalmars-d digitalmars-d at puremagic.com
Tue Oct 11 09:59:56 PDT 2016


Hi All,

   Need your help, on the below request.

Requirement:
Server:
2 socket listening to 2 different ports with one main program
	Socket1 Port1 (Used for receiving user request(user data))
	Socket2 Port2 (Used for system request(system data))

User request arrives via Socket1:Port1 needs to be sent 
Socket2:Port2
Once the request arrives then the request has to be sent to the 
Manger(another server) via Socket2:Port2

I was able to program to run multiple socket and send request to 
Socket1:Port1 but not able to send the same request to 
Socket2:Port2 tried both options sendTo and receiveFrom but no 
luck.

Note: the user request should to directly reach the 
Manger(another server) it should is always follow the data 
communication layer which is Socket2:Port2 as the
server Manger will connect via Socket2:Port2(only) to receive 
data.


void main () {
auto ext  = new Thread(&ext).start();
auto int  = new Thread(&int).start();
}

void ext () {
ushort extport  = 1120;
Socket ext;
char[1024] buf;
Address mainserver = new InternetAddress("server1", 1121);
ext = new TcpSocket();
ext.bind(1120);
ext.listen(1);
ext.accpet();
ext.receive(buf[]);
writeln(buf[0..1024]);
ext.sendTo(buf[0..1024], SocketFlags.NONE, mainserver);
}

void int () {
ushort intport  = 1121;
Socket int;
char[1024] buf;
Address mainserver = new InternetAddress("server1", 1120);
Address manager = new InternetAddress("server1", 1120);
int = new TcpSocket();
int.bind(1120);
int.listen(1);
int.accpet();
int.receive(buf[0..1024], SocketFlags.NONE, mainserver);
writeln(buf[0..1024]);
int.sendTo(buf[0..1024], SocketFlags.NONE, manager);
}


From,
Vino.B


More information about the Digitalmars-d mailing list