制作会员手机网站网站开发出来有后台么
- 作者: 五速梦信息网
- 时间: 2026年04月20日 03:46
当前位置: 首页 > news >正文
制作会员手机网站,网站开发出来有后台么,如何查看网站是哪家公司做的?,中山顺德网站建设解决 怎么解决#xff0c;就是 日志别输出到 cmd 就行了。就行了。就行了。 java -jar demo.jar output.log 21 最近写东西#xff0c;遇到了 程序偶尔卡死的情况。是java -jar 启动的。具体卡死为#xff1a;http请求超级卡顿 或 偶尔反应好多个请求就是 日志别输出到 cmd 就行了。就行了。就行了。 java -jar demo.jar output.log 21 最近写东西遇到了 程序偶尔卡死的情况。是java -jar 启动的。具体卡死为http请求超级卡顿 或 偶尔反应好多个请求或 tcp Server 粘包无法收取消息。直到我晃了晃 cmd 窗口最大化最小化程序竟然动了日志又输出了。终于终于明白了Window cmd 即要保证正常输出又要保证性能不卡死你的程序那你的程序又输出了很多很多日志那cmd窗口怎么办呢只有卡死你的程序了。 怀疑流程 因为遇到的是 http请求 和 tcp server 或同时能用同时不能用或只能用一个。怀疑1是 bio tcp server出现了问题用了 nio 还一样疯了。怀疑2spring boot 或 spring框架的问题 或 开线程等等问题最终各种启动 config配置类配置bean。在 main方法。使用postConstruct 等等等最后还是没找到问题 //ApplicationContext context//PostConstruct//AsyncEventListener(ApplicationReadyEvent.class)/Componentpublic class TcpServerListener implements ApplicationListenerWebServerInitializedEvent {Autowiredprivate UpdateServer updateServer;Overridepublic void onApplicationEvent(WebServerInitializedEvent event) {//int serverPort event.getWebServer().getPort();// 在此处添加代码以创建和启动 TCP 服务器updateServer.startServer(8082);}}/ BIO //Component public class UpdateServer {/SpringBootApplicationpublic class MyApplication {public static void main(String[] args) {SpringApplication.run(MyApplication.class, args);}EventListener(ApplicationReadyEvent.class)public void startServerSocket() throws IOException {// 创建ServerSocket并绑定端口ServerSocket serverSocket new ServerSocket(8080);// 启动一个新线程来接受客户端连接new Thread(() - {while (true) {try {// 接受客户端连接Socket clientSocket serverSocket.accept();// 处理客户端请求可以在这里实现自己的逻辑// 关闭客户端连接clientSocket.close();} catch (IOException e) {e.printStackTrace();}}}).start();}}//Componentpublic class TcpServerListener implements ApplicationListenerWebServerInitializedEvent {Autowiredprivate UpdateServer updateServer;Overridepublic void onApplicationEvent(WebServerInitializedEvent event) {//int serverPort event.getWebServer().getPort();// 在此处添加代码以创建和启动 TCP 服务器updateServer.startServer(8082);}}//*** TCP升级网关///Resource//private TcpUpdateMapper tcpUpdateMapper;/** Redis*///Resource//private RedisUtil redisUtil;//new Thread(() - { }).start();//PostConstruct//Async/public void startServer() throws Exception {//开启TCP ServerServerSocket serverSocket new ServerSocket(8082);log.info(服务端打开了 Server started on port {}, 8082);while (true) {//等待连接Socket socket serverSocket.accept();//获取 输入流DataInputStream inputStream new DataInputStream(socket.getInputStream());DataOutputStream outputStream new DataOutputStream(socket.getOutputStream());log.info(服务端收到了连接Accepted connection from client: {}, socket.getInetAddress());//读取的字节数byte[] buffer new byte[380];//1024//真正读取到了多少个int bytesRead;//循环进行读取while ((bytesRead inputStream.read(buffer)) ! -1) {//处理二进制数据processBinaryData(buffer, bytesRead, socket, outputStream);}//循环读取正常每次都会读取完毕inputStream.close();outputStream.close();socket.close();}//死循环接收连接}//初始化方法结束///关闭输入流//socket.shutdownInput();//关闭输出流关闭 Socket//socket.shutdownOutput();//关闭Socket//socket.close();NIO Configuration public class TcpServerConfig {/*** TCP升级网关/Resourceprivate TcpUpdateMapper tcpUpdateMapper;/** Redis*/Resourceprivate StringRedisTemplate stringRedisTemplate;Value(${tcp.ip})private String tcpIp;//ApplicationContext context//PostConstruct//AsyncEventListener(ApplicationReadyEvent.class)public void startServer() {// throws IOException//异步执行//ThreadUtil.execAsync(() - {try {//打开选择器Selector selector Selector.open();//打开通道ServerSocketChannel serverSocketChannel ServerSocketChannel.open();//非阻塞serverSocketChannel.configureBlocking(false);//本机IPserverSocketChannel.bind(new InetSocketAddress(tcpIp, 8082));//进行注册serverSocketChannel.register(selector, SelectionKey.OP_ACCEPT);log.info(Server started on port 8082);while (true) {//打开通道int readyChannels selector.select();//校验下if (readyChannels 0) {continue;}//获取所有的keySetSelectionKey selectedKeys selector.selectedKeys();//取得迭代器IteratorSelectionKey keyIterator selectedKeys.iterator();//如果存在while (keyIterator.hasNext()) {//获取这个keySelectionKey key keyIterator.next();//如果是个连接if (key.isAcceptable()) {//打开这个通道SocketChannel clientSocketChannel serverSocketChannel.accept();//非阻塞的clientSocketChannel.configureBlocking(false);//注册为可读clientSocketChannel.register(selector, SelectionKey.OP_READ);log.info(收到连接Accepted connection from: {}, clientSocketChannel.getRemoteAddress());} else if (key.isReadable()) {//如果是可读获取通道SocketChannel clientSocketChannel (SocketChannel) key.channel();//读取数量ByteBuffer buffer ByteBuffer.allocate(38);//1024//真实读取到了多少个int bytesRead -1;try {//这里报错了增加防护如果防护这个nio就断了bytesRead clientSocketChannel.read(buffer);} catch (Exception e) {log.info(未读取到);e.printStackTrace();}//未读取到 关闭if (bytesRead -1) {clientSocketChannel.close();} else if (bytesRead 0) {//读取到了buffer.flip();//读到这个字节里byte[] data new byte[bytesRead];buffer.get(data);//处理逻辑processBinaryData(data, bytesRead, clientSocketChannel);//String message new String(data).trim();//System.out.println(Received message: message);//清理buffer.clear();}//读到了}//是可读的//移除keykeyIterator.remove();}//如果存在}//死循环} catch (Exception e) {e.printStackTrace();}//}, MyTcpServerThread).start(); }//有错误往外层抛private void sendUpdateMessage(SocketChannel clientSocketChannel) {//去空格redisData redisData.replace( , );//转为bytebyte[] binaryData hexStringToBytes(redisData);//申请字节ByteBuffer buffer ByteBuffer.allocate(binaryData.length);//写入buffer.put(binaryData);buffer.flip();//循环写入while (buffer.hasRemaining()) {try {clientSocketChannel.write(buffer);log.info(发送了一次升级的消息);} catch (IOException e) {log.info(发送升级失败);e.printStackTrace();}}}
- 上一篇: 制作购物网站百度网络营销中心app
- 下一篇: 制作简易网站模板网站左侧导航代码
相关文章
-
制作购物网站百度网络营销中心app
制作购物网站百度网络营销中心app
- 技术栈
- 2026年04月20日
-
制作公司网站的流程阿里云域名注册步骤
制作公司网站的流程阿里云域名注册步骤
- 技术栈
- 2026年04月20日
-
制作个人网站的六个步骤网页美工软件
制作个人网站的六个步骤网页美工软件
- 技术栈
- 2026年04月20日
-
制作简易网站模板网站左侧导航代码
制作简易网站模板网站左侧导航代码
- 技术栈
- 2026年04月20日
-
制作教育类网站建设旅行网站策划书
制作教育类网站建设旅行网站策划书
- 技术栈
- 2026年04月20日
-
制作平台网站费用狗和女主人做爰网站
制作平台网站费用狗和女主人做爰网站
- 技术栈
- 2026年04月20日
