Java – a network that shuts down ports at school

I teach an introductory programming course in high school. I'm providing a network project for my students I think it will be very feasible for them to play a warship game. I think they will really be noticed I can use the socket on my home computer to do this, but at school, all ports are closed, and they are not open to me

Does it work (like having a web service to process transit information)? Any ideas?

The course is basic and the students don't have much background - I need to simplify as much as possible

Solution

This servlet should work in ads posted in comments (not tested):

Send messages and messages with URL parameters

Receive a message with get (receiver ID) Returns a message, or if there is no message The browser should be used for testing

In the real world, getting requests should not really change the state of the server I will only run this course for the time, because anyone can send any ID and anyone can read anything with any ID

public class SimpleMessageServlet extends HttpServlet {
  private Map<String,String> messages = new HashMap<String,String>();

  public void doGet(HttpServletRequest request,HttpServletResponse response) 
       throws ServletException,IOException {
    String to = request.getParameter("to");
    String message = request.getParameter("message");
    if (to != null && from != null && message != null) {
      messages.put(to,message);
    }
    response.setContentType("text/plain");
    String get = request.getParameter("get");
    if (get != null) {
      String result = messages.remove(get);
      if (result != null) {
        PrintWriter out = response.getWriter();
        out.println(result);
      }
    }
 }

Edit: it is simplified to store only one message per address. It should be sufficient for round based games. Buffering will only increase the complexity of client logic (eliminate outdated conversion data in previous matches, etc.) It may make sense to synchronize clients in some way, such as sending a "start" signal before sending forwarding and discarding any information before receiving a "start" Unfortunately, this will require polling, and it will be better to use peer sockets

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>