开发者

how I can send a received data from any port to another machine?

I want to implement a program that performs communication between more than 2 computers.

I will have a computer that send a query to a computer which is a server on port 2222, for example. This server will always listen to get a query. When it gets a query, it will send it to another machine which is a server on port 4444. and then a query will be run on the last machine then send back.

Illustration ::::

  1. query sender ------> first machine ( port 2222 ) ------> second machine ( port 4444 )

  2. second machine runs query

  3. second machine ( port 4444 )------> first machine ( port 2222 ) ------> query sender

Can you please tell me how I can send the received query from first machine to second machin开发者_运维百科e? To be more clear how I can send a received data from any port to another machine?

Thank you very much.


On the first machine, simply listen on port 2222, read the incoming queries, then open a Socket to the second machine on port 4444 (the second machine is listening on port 4444), which processes the query.

The reverse route is just the same in reverse. When the result is found, a Socket can be used to connect to the first machine, with the result, and then the first machine sends the result back out where it came from.

Both the first and second machine will need to utilize ServerSocket (for incoming connections) as well as use the Socket class to send results back.

As Suraf Chandran has explained, the networking api is where you need to start to understand the concepts behind this. If you've never done network programming before in Java, then it's important you go through the tutorial first.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜