shikeyin
2024-01-11 65da8373531677b1c37a98f53eaa30c892f35e5a
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
package com.iplatform.tcp.client;
 
import com.walker.infrastructure.utils.JsonUtils;
import com.walker.tcp.websocket.HelloRequest;
import org.java_websocket.client.WebSocketClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.RequestMapping;
 
@SpringBootApplication(scanBasePackages = {"com.walker","com.iplatform"})
public class ClientApplication {
 
    @Autowired
    private WebSocketClient webSocketClient;
 
    public static void main(String[] args) throws Exception{
        SpringApplication.run(ClientApplication.class, args);
 
//        TimeUnit.SECONDS.sleep(3);
//        TextSimilarityEngine textSimilarityEngine = BeanContextAware.getBeanByType(TextSimilarityEngine.class);
//        textSimilarityEngine.dropTable("course_info");
//        System.out.println("drop table: course_info");
//
//        WaitConsoleInput.waitInput();
    }
 
    @RequestMapping("/send")
    public String send(String name){
        HelloRequest request = new HelloRequest();
        request.setMessageId("messageId:hello");
        request.setName(name);
 
        try {
            String data = JsonUtils.objectToJsonString(request);
            webSocketClient.send(data.getBytes());
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        return "发送成功";
    }
 
}