whyclxw
2024-01-27 cf2df97ee7c5bb861526ef0ec9beaa174c04c872
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package com.lxw.test3d.Service;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.lxw.test3d.dto.Response;
import com.lxw.test3d.mapper.SocketCmdMapper;
import com.lxw.test3d.pojo.SocketCmd;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import javax.annotation.Resource;
 
@Service
public class SocketCmdService {
    @Autowired(required = false)
    private SocketCmdMapper mapper;
 
    //启动socket通讯
    public Response startSocket(String ip, int port) {
        new Thread(){
            @Override
            public void run() {
                while (true){
                    int cmd=getCmd();
                    if(cmd==72){
                        break;
                    }else{
                        System.out.println(1111);
                    }
                    try {
                        Thread.sleep(2000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        }.start();
        return new Response().set(1);
    }
 
    public int getCmd(){
        int cmd=0;
        QueryWrapper wrapper=new QueryWrapper();
        wrapper.last("limit 1");
        SocketCmd socketCmd=mapper.selectOne(wrapper);
        if(socketCmd!=null){
            cmd=socketCmd.getSocketCmd();
        }
        return cmd;
    }
}