UDP server stop working after a while


#21

that

Since you have worked quite a lot with this chip, would you recommend other actions to be performed or added in the case switch operations?


#22

What is switch operations in your context?


#23

Sorry, I have mean the C case handling

 while(1){
     uint8_t udp_socket_message = getSn_SR(udpServerSocket);
     switch(udp_socket_message){
       case SOCK_UDP: do work here; disconnect(udpServerSocket); break;
       case SOCK_LISTEN: break;
       case SOCK_ESTABLISHED: break;
       case SOCK_CLOSE_WAIT: disconnect(udp_socket_message); break;
       case SOCK_INIT: listen(udp_socket_message); break;
       case SOCK_CLOSED: if(!socket(udp_socket_message, Sn_MR_UDP, UDP_SERVER_PORT, 0x00)) ...; break; //re-use socket
     }

How would you normally thread each SnSR status after reading it. Do you check all socket status or just a few? Anything specific you recommend.

Thanks.


#24

What I can tell you that you have two vehicles how to check status of the socket - through interrupts (using IMR/IR register and/or hardware interrupt line itself), and through status register. They can and should be combined. However if you use only SR then it gives full understanding of the state, but using interrupt you only get notification on state change and anyway need to use SR. Probably it is not applicable to you project, but just keep it in mind.
Regarding your question on the case statement - it is just initial example how it could look like, the implementation fully depends on your needs - how you query sockets and their statuses, when you send data to remote peer (in terms of high level communication implementation), and how you manage concurrent data transfers. And from low level implementation access and process flow of the socket should obey those W5100 manual pages about TCP server/client and UDP.
About process flow: you can see it in manual, also see diagram on page 28 (it is a little messy, but as you study the process you will be able to understand it in full). There’re some status codes which are not listed BTW, but the idea for TCP that socket sequentially passes all the stages from 0x13 to 0x1E (or so). If socket has stuck in some state, you probably did something wrong before - in this connection or in managing/closing previous connection. Depends on scenario.


#25

When I try and connect using different computers at first it works but after some time it just stops; the connection is “terminated”. Also, ignore the game.player stuff, it is just a player of mine.

This is my code:

Client:

public class GameClient extends Thread {
  private InetAddress ipAddress;
  private DatagramSocket socket;
  private Main game;

  public GameClient(Main main, String ipAddress) {
    this.game = main;
    try {
      this.socket = new DatagramSocket();
      this.ipAddress = InetAddress.getByName(ipAddress);
    } catch (SocketException e) {
      e.printStackTrace();
    } catch (UnknownHostException e) {
      e.printStackTrace();
    }
  }
  public void run() {
    while (true) {
      byte[] data = new byte[1024];
      DatagramPacket packet = new DatagramPacket(data, data.length);
      try {
        socket.receive(packet);
      } catch (IOException e) {
        e.printStackTrace();
      }
      String message = new String(packet.getData());
      message = message.trim();
      if (message.startsWith("00")) {
        System.out.println("Player connected. Got server response...");
        String msg = "01" + game.player.getPos();
        sendData(msg.getBytes());
      }
      if (message.startsWith("01")) {
        message = message.substring(2);
        List<String> coords = Arrays.asList(message.split(","));
        game.updateMP(coords);
see: https://luckypatcher.pro/
https://kodi.software/
https://plex.software/