Listeners

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi

Is it possible to have one application to be listening to two ports for incoming data

Can I configure a port to both send and to receive data

Regard
Viola
 
Is it possible to have one application to be listening to two ports for
incoming data?

Yes. You'll probably want to look at the async method calls, so you dont
block on the first call you make (or, run each port on a separate thread).
Can I configure a port to both send and to receive data?

I think that depends of the protocols you are using, and exactly what you
mean by "both send and to receive data". If you are doing session oriented
stuff, you can send and receive when you are connected, but usually you
either listen for incoming connections, or connected to a listening port.

Nick Holmes.
 
Thank you Nick, for your response
Yes. You'll probably want to look at the async method calls, so you don
block on the first call you make (or, run each port on a separate thread)

Could you please explain what you mean by 'block on the first call'
I think that depends of the protocols you are using, and exactly what yo
mean by "both send and to receive data". If you are doing session oriente
stuff, you can send and receive when you are connected, but usually yo
either listen for incoming connections, or connected to a listening port

I would be using TCP. I have a client, which listens to two servers, server1 and server2. The client would listen on port1 for incoming data from server1, and then process the data and pass it on to server2 through port2. Server2 dials in to the client with some paramters and fetches data from the client's database, (depending on the paramters passed,) and passes the same back to server2. So, the client would be listening to port1 for data from server1 and port2 for incoming calls from server2, so that the client would process data on the client's database and send the processed data back to server2

In this scenario, can I have an application at the client to be listening to port1 and port2 at the same time? Here port2 would be used to send data (from server1) and receive requests (from server2). Can this be done and what would be the best way to implement this

Thanks once agai
Viol
 
By "block" I mean that when you call Socket.Accept, that call will not
return (i.e. block further exexuction of your code) until a connection
attempt is made (which is clearly beyond your control). If you want to
listen on more than one port, then you need to either call BeginAccept, or
create a thread for each port.

Dont want to sound pedantic, but in my world-view, clients dont listen to
servers, rather servers listen for clients (call me simplistic, but it works
for me).

Anyway, it sounds to me like you need to listen on two ports for servers 1
and 2, and have a third port fo sending to server 2 (but its possible I have
misunderstoon what you are trying to do).

Anyway, if you have a socket that is in currently waiting to accept, I dont
beleive you can then initiate an outgoing connection on it.

Nick.

Viola said:
Thank you Nick, for your response.
thread).

Could you please explain what you mean by 'block on the first call'?


I would be using TCP. I have a client, which listens to two servers,
server1 and server2. The client would listen on port1 for incoming data from
server1, and then process the data and pass it on to server2 through port2.
Server2 dials in to the client with some paramters and fetches data from the
client's database, (depending on the paramters passed,) and passes the same
back to server2. So, the client would be listening to port1 for data from
server1 and port2 for incoming calls from server2, so that the client would
process data on the client's database and send the processed data back to
server2.
In this scenario, can I have an application at the client to be listening
to port1 and port2 at the same time? Here port2 would be used to send data
(from server1) and receive requests (from server2). Can this be done and
what would be the best way to implement this?
 
Nick, you are correct, ideally, the machine which listens to requests is called a server! Just that I have a process running on server2 to accept data sent from server1 through the client; I called them so to avoid confusions
By "block" I mean that when you call Socket.Accept, that call will no
return (i.e. block further exexuction of your code) until a connectio
attempt is made (which is clearly beyond your control). If you want t
listen on more than one port, then you need to either call BeginAccept, o
create a thread for each port

Got it!! Thanks! Which is a better choice; using threads or asynchronous method calls
Anyway, it sounds to me like you need to listen on two ports for servers
and 2, and have a third port fo sending to server 2 (but its possible I hav
misunderstoon what you are trying to do)

I think you have misunderstood me! I need to listen to two ports port1 and port1 for server1 and server2, respectively; and use the same port (port2) to send to server2
1. data received from port
2. reponse of the query that would be sent from server1 through port1 to the clien

Can this be achieved by issuing a BeginAccept on the client for port2 to receive query from server2; and in the meanwhile, if data has been recieved from port1, pass on this data to the server2 through port2 itself

I don't know if I am talking sense! Just trying to figure out a way to program this

Thanks once again for responding to my queries

Viol
 
Got it!! Thanks! Which is a better choice; using threads or asynchronous
method calls?

The async methods use threads internally, anyway. I would say, more than any
other consideration, use the approach that you are most comfortable to code
with.
Can this be achieved by issuing a BeginAccept on the client for port2 to
receive query from server2; and in the meanwhile, if data has been recieved
from port1, pass on this data to the server2 through port2 itself?

I would be looking to use 3 ports (2 listeners, and one sender). I can see
no benefit from forcing this dual use of one of you ports, and life will be
a lot easier if you use three ports.

Nick.
 
The async methods use threads internally, anyway. I would say, more than an
other consideration, use the approach that you are most comfortable to cod
with

For me both the concepts are new. Never done programming using threads or async methods! Can you give me links to good articles on both

Thanks for bearing with me this far
I would be looking to use 3 ports (2 listeners, and one sender). I can se
no benefit from forcing this dual use of one of you ports, and life will b
a lot easier if you use three ports

If using 3 ports would be easier to work with, I would rather use 3 ports! Just clarifying

You mean to say that the third port should be used to send data to server
1. data passed from server1
2. results of the query from server

And port1 and port2 should be used only as listening ports

Thanks once again
Regards
Viol
 
If you have not done any multi-threading work, and you are on commercial
timescales, BeginXXX would be my recommendation.

Yes, 3 ports; 2 listeners and 1 sender.

Nick.

Viola said:
For me both the concepts are new. Never done programming using threads or
async methods! Can you give me links to good articles on both?
 
Thanks a lot Nick. Your suggestions have been very useful

I have another situation and query here, at server1, which I hope you would not mind clarifying. I take the liberty of asking another related query

The port1 which the client would be listening to on server1, would I be able to use the same port to send data to server1? The reason why I am asking you this is because, the server1 is designed by another company and this is the port they are using to send and receive data from the client. I don't have control on the server1 to use 2 ports, one to send and the other to receive. How will be able to achieve this? Can I use a BeginAccept for listening on port1 (to recieve data from server1)and in the meanwhile, when I receive data from server2 which needs to be passed to server1, can I disconnect the connection with server1 and then reconnect it to send data, and after processing, disconnect and then give a BeginAccept to conitnue to listen? Will I be able to implement it this way? Or is there a better way to do this

Thanks a ton
Regards
Viola
 
Back
Top