一个Socket服务器样板程序

TCP服务器和客户端的创建(socket/socketserver) 1 本文记录针对python网络编程学习过程中的socket部分进行记录与总结,内容仅仅涉及最粗浅的部分,日后或许会进行更新与扩展。 2 本文涉及的socket数据传输均使用bytes类型,因此在python3环境下,需要特别注意字符串的编码与解码。 1 socket模块 1.1 创建TCP服务器 - socket.socket() 1.2 创建TCP客户端 - socket... 阅读详情
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script> 这是一个非常好的Socket服务器样板程序,这个socket服务器可以为你建立指定的监听端口、客户端请求响应机制等一些服务器所具备的基本框架



/*

 * Copyright (c) 2000 David Flanagan.  All rights reserved.

 * This code is from the book Java Examples in a Nutshell, 2nd Edition.

 * It is provided AS-IS, WITHOUT ANY WARRANTY either expressed or implied.

 * You may study, use, and modify it for any non-commercial purpose.

 * You may distribute it non-commercially as long as you retain this notice.

 * For a commercial use license, or to purchase the book (recommended),

 * visit http://www.davidflanagan.com/javaexamples2.

 */



import java.io.*;

import java.net.*;

import java.util.*;



/**

 * This class is a generic framework for a flexible, multi-threaded server.

 * It listens on any number of specified ports, and, when it receives a 

 * connection on a port, passes input and output streams to a specified Service

 * object which provides the actual service.  It can limit the number of

 * concurrent connections, and logs activity to a specified stream.

 **/

public class Server {

    /**

     * A main() method for running the server as a standalone program.  The

     * command-line arguments to the program should be pairs of servicenames

     * and port numbers.  For each pair, the program will dynamically load the

     * named Service class, instantiate it, and tell the server to provide

     * that Service on the specified port.  The special -control argument

     * should be followed by a password and port, and will start special

     * server control service running on the specified port, protected by the

     * specified password.

     **/

    public static void main(String[] args) {

        try {

            if (args.length < 2)  // Check number of arguments

                throw new IllegalArgumentException("Must specify a service");

            

            // Create a Server object that uses standard out as its log and

            // has a limit of ten concurrent connections at once.

            Server s = new Server(System.out, 10);



            // Parse the argument list

            int i = 0;

            while(i < args.length) {

                if (args[i].equals("-control")) {  // Handle the -control arg

                    i  ;

                    String password = args[i  ];

                    int port = Integer.parseInt(args[i  ]);

      // add control service

                    s.addService(new Control(s, password), port);

                } 

                else {

                    // Otherwise start a named service on the specified port.

                    // Dynamically load and instantiate a Service class

                    String serviceName = args[i  ];

                    Class serviceClass = Class.forName(serviceName); 

                    Service service = (Service)serviceClass.newInstance();

                    int port = Integer.parseInt(args[i  ]);

                    s.addService(service, port);

                }

            }

        }

        catch (Exception e) { // Display a message if anything goes wrong

            System.err.println("Server: "   e);

            System.err.println("Usage: java Server "  

          "[-control  ] "  

          "[  ... ]");

            System.exit(1);

        }

    }



    // This is the state for the server

    Map services;                   // Hashtable mapping ports to Listeners

    Set connections;                // The set of current connections

    int maxConnections;             // The concurrent connection limit

    ThreadGroup threadGroup;        // The threadgroup for all our threads

    PrintWriter logStream;          // Where we send our logging output to



    /**

     * This is the Server() constructor.  It must be passed a stream 

     * to send log output to (may be null), and the limit on the number of

     * concurrent connections.  

     **/

    public Server(OutputStream logStream, int maxConnections) { 

        setLogStream(logStream);

        log("Starting server");

        threadGroup = new ThreadGroup(Server.class.getName());

 this.maxConnections = maxConnections;

        services = new HashMap();

 connections = new HashSet(maxConnections);

    }

    

    /** 

     * A public method to set the current logging stream.  Pass null

     * to turn logging off

     **/

    public synchronized void setLogStream(OutputStream out) {

        if (out != null) logStream = new PrintWriter(out);

        else logStream = null;

    }



    /** Write the specified string to the log */

    protected synchronized void log(String s) { 

        if (logStream != null) {

            logStream.println("["   new Date()   "] "   s);

            logStream.flush();

        }

    }

    /** Write the specified object to the log */

    protected void log(Object o) { log(o.toString()); }

    

    /**

     * This method makes the server start providing a new service.

     * It runs the specified Service object on the specified port.

     **/

    public synchronized void addService(Service service, int port)

 throws IOException

    {

        Integer key = new Integer(port);  // the hashtable key

        // Check whether a service is already on that port

        if (services.get(key) != null) 

            throw new IllegalArgumentException("Port "   port  

            " already in use.");

        // Create a Listener object to listen for connections on the port

        Listener listener = new Listener(threadGroup, port, service);

        // Store it in the hashtable

        services.put(key, listener);

        // Log it

        log("Starting service "   service.getClass().getName()   

     " on port "   port);

        // Start the listener running.

        listener.start();

    }

    

    /**

     * This method makes the server stop providing a service on a port.

     * It does not terminate any pending connections to that service, merely

     * causes the server to stop accepting new connections

     **/

    public synchronized void removeService(int port) {

        Integer key = new Integer(port);  // hashtable key

        // Look up the Listener object for the port in the hashtable

        final Listener listener = (Listener) services.get(key);

        if (listener == null) return;

        // Ask the listener to stop

        listener.pleaseStop();

        // Remove it from the hashtable

        services.remove(key);

        // And log it.

        log("Stopping service "   listener.service.getClass().getName()   

     " on port "   port);

    }

    

    /** 

     * This nested Thread subclass is a "listener".  It listens for

     * connections on a specified port (using a ServerSocket) and when it gets

     * a connection request, it calls the servers addConnection() method to

     * accept (or reject) the connection.  There is one Listener for each

     * Service being provided by the Server.

     **/

    public class Listener extends Thread {

        ServerSocket listen_socket;    // The socket to listen for connections

        int port;                      // The port we're listening on

        Service service;               // The service to provide on that port

        volatile boolean stop = false; // Whether we've been asked to stop



        /**

  * The Listener constructor creates a thread for itself in the

  * threadgroup.  It creates a ServerSocket to listen for connections

  * on the specified port.  It arranges for the ServerSocket to be

  * interruptible, so that services can be removed from the server.

  **/

        public Listener(ThreadGroup group, int port, Service service) 

     throws IOException

 {

            super(group, "Listener:"   port);      

            listen_socket = new ServerSocket(port);

            // give it a non-zero timeout so accept() can be interrupted

            listen_socket.setSoTimeout(600000);

            this.port = port;

            this.service = service;

        }



        /** 

  * This is the polite way to get a Listener to stop accepting

  * connections

  ***/

        public void pleaseStop() {

            this.stop = true;              // Set the stop flag

            this.interrupt();              // Stop blocking in accept()

     try { listen_socket.close(); } // Stop listening.

     catch(IOException e) {}

        }

        

        /**

  * A Listener is a Thread, and this is its body.

  * Wait for connection requests, accept them, and pass the socket on

  * to the addConnection method of the server.

  **/

        public void run() {

            while(!stop) {      // loop until we're asked to stop.

                try {

                    Socket client = listen_socket.accept();

                    addConnection(client, service);

                } 

                catch (InterruptedIOException e) {} 

                catch (IOException e) {log(e);}

            }

        }

    }

 

    /**

     * This is the method that Listener objects call when they accept a

     * connection from a client.  It either creates a Connection object 

     * for the connection and adds it to the list of current connections,

     * or, if the limit on connections has been reached, it closes the 

     * connection. 

     **/

    protected synchronized void addConnection(Socket s, Service service) {

 // If the connection limit has been reached

 if (connections.size() >= maxConnections) {

     try {

  // Then tell the client it is being rejected.

  PrintWriter out = new PrintWriter(s.getOutputStream());

  out.print("Connection refused; "  

     "the server is busy; please try again later./n");

  out.flush();

  // And close the connection to the rejected client.

  s.close();

  // And log it, of course

  log("Connection refused to "  

      s.getInetAddress().getHostAddress()  

      ":"   s.getPort()   ": max connections reached.");

     } catch (IOException e) {log(e);}

 }

 else {  // Otherwise, if the limit has not been reached

     // Create a Connection thread to handle this connection

     Connection c = new Connection(s, service);

     // Add it to the list of current connections

     connections.add(c);

     // Log this new connection

     log("Connected to "   s.getInetAddress().getHostAddress()  

  ":"   s.getPort()   " on port "   s.getLocalPort()  

  " for service "   service.getClass().getName());

     // And start the Connection thread to provide the service

     c.start();

 }

    }



    /**

     * A Connection thread calls this method just before it exits.  It removes

     * the specified Connection from the set of connections.

     **/

    protected synchronized void endConnection(Connection c) {

 connections.remove(c);

 log("Connection to "   c.client.getInetAddress().getHostAddress()  

     ":"   c.client.getPort()   " closed.");

    }



    /** Change the current connection limit */

    public synchronized void setMaxConnections(int max) {

 maxConnections = max;

    }



    /**

     * This method displays status information about the server on the

     * specified stream.  It can be used for debugging, and is used by the

     * Control service later in this example.

     **/

    public synchronized void displayStatus(PrintWriter out) {

 // Display a list of all Services that are being provided

 Iterator keys = services.keySet().iterator();

 while(keys.hasNext()) {

     Integer port = (Integer) keys.next();

     Listener listener = (Listener) services.get(port);

     out.print("SERVICE "   listener.service.getClass().getName()

          " ON PORT "   port   "/n");

 }

 

 // Display the current connection limit

 out.print("MAX CONNECTIONS: "   maxConnections   "/n");



 // Display a list of all current connections

 Iterator conns = connections.iterator();

 while(conns.hasNext()) {

     Connection c = (Connection)conns.next();

     out.print("CONNECTED TO "  

        c.client.getInetAddress().getHostAddress()  

        ":"   c.client.getPort()   " ON PORT "  

        c.client.getLocalPort()   " FOR SERVICE "  

        c.service.getClass().getName()   "/n");

 }

    }



    /**

     * This class is a subclass of Thread that handles an individual

     * connection between a client and a Service provided by this server.

     * Because each such connection has a thread of its own, each Service can

     * have multiple connections pending at once.  Despite all the other

     * threads in use, this is the key feature that makes this a

     * multi-threaded server implementation.

     **/

    public class Connection extends Thread {

        Socket client;     // The socket to talk to the client through

        Service service;   // The service being provided to that client

 

        /**

  * This constructor just saves some state and calls the superclass

  * constructor to create a thread to handle the connection.  Connection

  * objects are created by Listener threads.  These threads are part of

  * the server's ThreadGroup, so all Connection threads are part of that

  * group, too.

  **/

        public Connection(Socket client, Service service) {

            super("Server.Connection:"  

    client.getInetAddress().getHostAddress()  

    ":"   client.getPort());

            this.client = client;

            this.service = service;

        }

 

        /**

  * This is the body of each and every Connection thread.

  * All it does is pass the client input and output streams to the

  * serve() method of the specified Service object.  That method is

  * responsible for reading from and writing to those streams to

  * provide the actual service.  Recall that the Service object has

  * been passed from the Server.addService() method to a Listener

  * object to the addConnection() method to this Connection object, and

  * is now finally being used to provide the service.  Note that just

  * before this thread exits it always calls the endConnection() method

  * to remove itself from the set of connections

  **/

        public void run() {

            try { 

                InputStream in = client.getInputStream();

                OutputStream out = client.getOutputStream();

                service.serve(in, out);

            } 

            catch (IOException e) {log(e);}

            finally { endConnection(this); }

        }

    }

    

    /**

     * Here is the Service interface that we have seen so much of.  It defines

     * only a single method which is invoked to provide the service.  serve()

     * will be passed an input stream and an output stream to the client.  It

     * should do whatever it wants with them, and should close them before

     * returning.

     *

     * All connections through the same port to this service share a single

     * Service object.  Thus, any state local to an individual connection must

     * be stored in local variables within the serve() method.  State that

     * should be global to all connections on the same port should be stored

     * in instance variables of the Service class.  If the same Service is

     * running on more than one port, there will typically be different

     * Service instances for each port.  Data that should be global to all

     * connections on any port should be stored in static variables.

     *

     * Note that implementations of this interface must have a no-argument 

     * constructor if they are to be dynamically instantiated by the main()

     * method of the Server class.

     **/

    public interface Service {

        public void serve(InputStream in, OutputStream out) throws IOException;

    }



    /**

     * A very simple service.  It displays the current time on the server

     * to the client, and closes the connection.

     **/

    public static class Time implements Service {

        public void serve(InputStream i, OutputStream o) throws IOException {

            PrintWriter out = new PrintWriter(o);

            out.print(new Date()   "/n");

            out.close();

            i.close();

        }

    }

    

    /**

     * This is another example service.  It reads lines of input from the

     * client, and sends them back, reversed.  It also displays a welcome

     * message and instructions, and closes the connection when the user 

     * enters a '.' on a line by itself.

     **/

    public static class Reverse implements Service {

        public void serve(InputStream i, OutputStream o) throws IOException {

            BufferedReader in = new BufferedReader(new InputStreamReader(i));

            PrintWriter out = 

                new PrintWriter(new BufferedWriter(new OutputStreamWriter(o)));

            out.print("Welcome to the line reversal server./n");

            out.print("Enter lines.  End with a '.' on a line by itself./n");

            for(;;) {

                out.print("> ");

                out.flush();

                String line = in.readLine();

                if ((line == null) || line.equals(".")) break;

                for(int j = line.length()-1; j >= 0; j--)

                    out.print(line.charAt(j));

                out.print("/n");

            }

            out.close();

            in.close();

        }

    }

    

    /**

     * This service is an HTTP mirror, just like the HttpMirror class

     * implemented earlier in this chapter.  It echos back the client's

     * HTTP request

     **/

    public static class HTTPMirror implements Service {

        public void serve(InputStream i, OutputStream o) throws IOException {

            BufferedReader in = new BufferedReader(new InputStreamReader(i));

            PrintWriter out = new PrintWriter(o);

            out.print("HTTP/1.0 200 /n");

            out.print("Content-Type: text/plain/n/n");

            String line;

            while((line = in.readLine()) != null) {

                if (line.length() == 0) break;

                out.print(line   "/n");

            }

            out.close();

            in.close();

        }

    }

    

    /**

     * This service demonstrates how to maintain state across connections by

     * saving it in instance variables and using synchronized access to those

     * variables.  It maintains a count of how many clients have connected and

     * tells each client what number it is

     **/

    public static class UniqueID implements Service {

        public int id=0;

        public synchronized int nextId() { return id  ; }

        public void serve(InputStream i, OutputStream o) throws IOException {

            PrintWriter out = new PrintWriter(o);

            out.print("You are client #: "   nextId()   "/n");

            out.close();

            i.close();

        }

    }

    

    /**

     * This is a non-trivial service.  It implements a command-based protocol

     * that gives password-protected runtime control over the operation of the 

     * server.  See the main() method of the Server class to see how this

     * service is started.  

     *

     * The recognized commands are:

     *   password: give password; authorization is required for most commands

     *   add:      dynamically add a named service on a specified port

     *   remove:   dynamically remove the service running on a specified port

     *   max:      change the current maximum connection limit.

     *   status:   display current services, connections, and connection limit

     *   help:     display a help message

     *   quit:     disconnect

     *

     * This service displays a prompt, and sends all of its output to the user

     * in capital letters.  Only one client is allowed to connect to this 

     * service at a time.

     **/

    public static class Control implements Service {

        Server server;             // The server we control

        String password;           // The password we require

        boolean connected = false; // Whether a client is already connected

 

        /**

  * Create a new Control service.  It will control the specified Server

  * object, and will require the specified password for authorization

  * Note that this Service does not have a no argument constructor,

  * which means that it cannot be dynamically instantiated and added as

  * the other, generic services above can be.

  **/

        public Control(Server server, String password) {

            this.server = server;

            this.password = password;

        }



        /**

  * This is the serve method that provides the service.  It reads a

  * line the client, and uses java.util.StringTokenizer to parse it

  * into commands and arguments.  It does various things depending on

  * the command.

  **/

        public void serve(InputStream i, OutputStream o) throws IOException {

            // Setup the streams

            BufferedReader in = new BufferedReader(new InputStreamReader(i));

            PrintWriter out = new PrintWriter(o);

            String line;  // For reading client input lines

     // Has the user has given the password yet?

            boolean authorized = false; 



            // If there is already a client connected to this service, display

            // a message to this client and close the connection.  We use a

            // synchronized block to prevent a race condition.

            synchronized(this) { 

                if (connected) { 

                    out.print("ONLY ONE CONTROL CONNECTION ALLOWED./n");

                    out.close();

                    return;

                }

                else connected = true;

            }



     // This is the main loop: read a command, parse it, and handle it

            for(;;) {  // infinite loop

                out.print("> ");           // Display a prompt

                out.flush();               // Make it appear right away

                line = in.readLine();      // Get the user's input

                if (line == null) break;   // Quit if we get EOF.

                try {

                    // Use a StringTokenizer to parse the user's command

                    StringTokenizer t = new StringTokenizer(line);

                    if (!t.hasMoreTokens()) continue;  // if input was empty

                    // Get first word of the input and convert to lower case

                    String command = t.nextToken().toLowerCase(); 

                    // Now compare to each of the possible commands, doing the

                    // appropriate thing for each command

                    if (command.equals("password")) {  // Password command

                        String p = t.nextToken();      // Get the next word

                        if (p.equals(this.password)) { // Is it the password?

                            out.print("OK/n");         // Say so

                            authorized = true;         // Grant authorization

                        }

                        else out.print("INVALID PASSWORD/n"); // Otherwise fail

                    }

                    else if (command.equals("add")) {  // Add Service command

                        // Check whether password has been given

                        if (!authorized) out.print("PASSWORD REQUIRED/n"); 

                        else {

                            // Get the name of the service and try to

                            // dynamically load and instantiate it.

                            // Exceptions will be handled below

                            String serviceName = t.nextToken();

                            Class serviceClass = Class.forName(serviceName);

                            Service service;

                            try {

    service = (Service)serviceClass.newInstance();

       }

                            catch (NoSuchMethodError e) {

                                throw new IllegalArgumentException(

             "Service must have a "  

      "no-argument constructor");

                            }

                            int port = Integer.parseInt(t.nextToken());

                            // If no exceptions occurred, add the service

                            server.addService(service, port);

                            out.print("SERVICE ADDED/n");    // acknowledge

                        }

                    }

                    else if (command.equals("remove")) { // Remove service

                        if (!authorized) out.print("PASSWORD REQUIRED/n");

                        else {

                            int port = Integer.parseInt(t.nextToken()); 

                            server.removeService(port); // remove the service

                            out.print("SERVICE REMOVED/n"); // acknowledge

                        }

                    }

                    else if (command.equals("max")) { // Set connection limit

                        if (!authorized) out.print("PASSWORD REQUIRED/n");

                        else {

                            int max = Integer.parseInt(t.nextToken()); 

                            server.setMaxConnections(max); 

                            out.print("MAX CONNECTIONS CHANGED/n");

                        }

                    }

                    else if (command.equals("status")) { // Status Display

                        if (!authorized) out.print("PASSWORD REQUIRED/n");

   else server.displayStatus(out);

                    }

                    else if (command.equals("help")) {  // Help command

                        // Display command syntax.  Password not required

                        out.print("COMMANDS:/n"   

      "/tpassword /n"  

      "/tadd  /n"  

      "/tremove /n"  

      "/tmax /n"  

      "/tstatus/n"  

      "/thelp/n"   

      "/tquit/n");

                    }

                    else if (command.equals("quit")) break; // Quit command.

                    else out.print("UNRECOGNIZED COMMAND/n"); // Error

  }

                catch (Exception e) {

                    // If an exception occurred during the command, print an

                    // error message, then output details of the exception.

                    out.print("ERROR WHILE PARSING OR EXECUTING COMMAND:/n"  

         e   "/n");

                }

            }

            // Finally, when the loop command loop ends, close the streams

            // and set our connected flag to false so that other clients can

            // now connect.

            connected = false;

            out.close();

            in.close();

        }    

    }

}





告别网络依赖:用Vue3+Leaflet和IIS搭建本地离线地图服务(附腾讯地图瓦片下载) 本文详细介绍了如何利用Vue3、Leaflet和IIS构建企业级离线地图解决方案,特别包含腾讯地图瓦片的下载与优化技巧。通过技术选型对比、IIS部署优化及Vue3与Leaflet的深度集成实战,帮助开发者在网络不稳定或完全离线的环境中实现高效地图服务部署。 阅读详情

相关推荐

基于STM32与W6100的IPv4/IPv6双栈回环服务器实现

嵌入式网络开发中,TCP/IP协议栈是实现设备联网的核心基础。传统软件协议栈如LwIP需要消耗大量MCU资源,而硬件协议栈芯片如W6100通过内置完整网络协议处理逻辑,将CPU从繁琐的协议解析中解放出来,显著提升系统效率与稳定性。这种硬件加速方案特别适合资源受限的嵌入式场景,为物联网设备提供可靠的网络连接能力。随着IPv4地址耗尽,IPv6成为物联网发展的必然趋势,双栈支持成为现代嵌入式设备的标配。本文通过一个具体的STM32F103VC与W6100硬件组合案例,详细解析如何利用硬件协议栈快速构建同时支持I

weixin_34267123的博客 633

基于Linux的socket编程模板

    在网络编程编程中,我们经常会遇到这样一种C/S架构,服务器端(Server)监听客户端(Client)发送过来的命令,然后解析该命令,并做对应的处理,最后返回处理结果(例如成功或者失败及原因)给客户端。     最近,在Linux下做网络编程,涉及的就是上面的这种需求,简单地整理了下自己的代码,分享在这里吧,供初学者参考。     首先说一下编程思路吧。     在这种情况客户端必须...

weixin_34245082的博客 212

【Unity3D】RTS Engine 笔记一

RTS Engine 中配置一个新场景, 初步认识GameManager、设置地形以及配置地形网格搜索

ViYeye的博客 1653

java编写socket的客户端程序

这里提供一个基本的双功样板程序,给需要编写简单的通信程序的朋友。发送部分是独立的线程,接收部分是在主线程工作。

weixin_39766667的博客 52

CTP开发实战:如何高效处理预埋单与委托单的完整流程(附代码示例)

本文深入探讨了CTP开发中预埋单与委托单的完整处理流程,从订单生命周期理解、核心代码实现到异步事件处理与系统健壮性构建。通过详细的代码示例和状态机分析,为开发者提供了构建高可靠订单处理系统的实战指南,重点解决了状态同步、异常恢复等关键工程挑战。

weixin_29234239的博客 118

1.triton镜像使用

1)拉取镜像2)启动容器指定模型仓库时可以执行server下的./fetch_model.sh,见2.2部分GPU版本的启动CPU版本的启动区别只在于--gpus=1这个参数注意:docker19.03之前的版本使用gpu要指定显卡硬件名,docker19.03之后的需要安装nvidia-container-toolkit或nvidia-container-runtime安装之后要重启docker查看gpus参数是否安装成功重新执行我遇到了如下错误先使用非GPU版本的。

天启的博客 2077

Python Socket学习之旅(一)

Socket概述 socket通常也称作"套接字",用于描述IP地址和端口,是一个通信链的句柄,应用程序通常通过"套接字"向 网络发出请求或者应答网络请求。 socket起源于Unix,而Unix/Linux基本哲学之一就是“一切皆文件”,对于文件用【打开】【读写】【关闭】 模式来操作。socket就是该模式的一个实现,socket即是一种特殊的文件,一些socket函数就是对其进行 ...

89

VS2103+Intel2013+MSMPI运行Fortran并行程序

VS2103+Intel2013+MSMPI运行Fortran并行程序MSMPI安装新建Fortran90项目编写Fortran并行程序在cmd运行编译完成的执行文件 MSMPI安装 我这里采用的是Microsoft MPI v9.0.1,可以点此下载。下载完成后同时安装msmpisdk.msi、msmpisetup.exe两个文件,安装位置默认即可。 其中msmpisdk.msi的默认安装路径在C:\Program Files (x86)\Microsoft SDKs\MPI,该文件包含了mpi环境所需

weixin_43176703的博客 2937

python tcp服务器模板_python SocketServer模块创建TCP服务器·

SocketServer 模块是标准库中的一个高级模块,他的目的是为了简化很多样板代码,他是创建网络客户端和服务器所必需的代码,这个模块中有为你创建的各种各样的模块类描述BaseServer包含核心服务器功能和mix-in类的钩子;仅用于推导,这样不会创建这个类的实例;可以使用TCPServer或UDPServer创建类的实例TCPServer/UDPServer基础的网络同步TCP/UDP服务器...

weixin_39625709的博客 83

Proteus下载安装快速入门:30分钟掌握全过程

手把手教你完成proteus下载安装,从环境配置到首次运行一气呵成,适合电子设计新手快速掌握仿真工具的核心操作步骤。

weixin_31974443的博客 895

YOLOv11改进 | 损失函数改进篇 | MPDIoU、InnerMPDIoU助力细节涨点(二次创新 + 代码解析)

本文为读者详细介绍了YOLOv11模型的最新改进,带来的改进机制是最新的损失函数MPDIoU和融合了最新的Inner思想的InnerMPDIoU(效果打爆之前的所有的损失函数提升检测精度和处理细节方面的作用。通过深入探讨MPDIoU和InnerMPDIoU(全网首发)的工作原理和实际代码实现,本文旨在指导读者如何将这些先进的损失函数技术应用到YOLOv11模型中,以提高其性能和准确性。文章内容涵盖从理论基础、代码实现,到实际教你如何添加本文的机制到你的模型中。

Snu77的博客 4030

NetAssistant 网络调试助手上手指南:一个窗口搞定 UDP 与 TCP 调试

写嵌入式固件的人最怕什么?调试网络通信时,改一个字节的数据要重新编译一次,或者开着三个终端来回敲命令。NetAssistant 这款基于 Qt 的跨平台网络调试助手,把 UDP、TCP 客户端、TCP 服务器三种模式的收发全部塞进一个窗口,点几下鼠标,就能完成以前要折腾半天的活儿。这篇教程会带你从编译装好,一路走到熟练使用它的文件传输和群聊转发,全程可以照做。 ## 它的定位:不是又一款"教学玩

gitblog_00595的博客 309

AI 模型优化与部署秘籍:从理论到实战

本文系统介绍了AI模型优化与部署的关键技术。模型剪枝通过去除冗余参数减小模型规模,量化技术降低计算精度以提升效率,蒸馏方法实现知识从大模型到小模型的迁移。TensorRT通过层融合和精度校准加速GPU推理,ONNX格式实现跨框架模型转换,TFLite则优化移动端部署。这些技术共同解决了AI模型在资源受限环境下的部署难题,显著提升了模型运行效率,为AI应用落地提供了重要支撑。

远程部署调试 运行安装 项目调试 二次开发 项目技术新 持续迭代 部分源码免费分享 247

netty socket超时设置_Netty框架学习及第一个Netty应用(建议收藏)

1.什么是Netty?Netty是一个利用Java的高级网络的能力,隐藏其背后的复杂性而提供一个易于使用的API的客户端/服务器框架。Netty提供高性能和可扩展性,让你可以自由地专注于你真正感兴趣的东西。2.发展历史:网络发展初期,花费很多时间学习socket的复杂、寻址等,在C socket库上进行编码,并需要在不同的操作系统上做不同的处理。Java早期版本(1995-2002)介绍了足够的面...

weixin_39621075的博客 344

R语言生存分析之竞争风险模型

R语言生存分析之竞争风险模型 竞争风险模型(Competing Risk Model)是一种处理多种潜在结局生存数据的分析方法,早在1999年Fine和Gray就提出了部分分布的半参数比例风险模型,通常使用的终点指标是累积发生率函数(cumulative incidence function,CIF)。 研究中结局事件可能有多个,某些结局将阻止感兴趣事件的出现或影响其发生的概率,各结局事件形成“竞争”关系,互为竞争风险事件。 竞争风险模型( Competing Risk Model ) : 指

data+scenario+science+insight 5248

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

Jackett 完全指南:把数百个种子站点聚合成统一搜索 API

往媒体库追一部新剧时,资源往往散落在几十个种子站里:每个站的搜索入口不同、返回格式不同,想自动化就得逐个对接。Jackett 是一款开源的种子资源聚合代理服务,把约 600 个公开、半私人、私人 tracker 的搜索协议统一翻译成 Torznab 和 TorrentPotato 两种标准格式——一次查询拿到所有已配置站点的结果,下游工具只需对接一次。 ## 快速上手:从源码构建并启动 Jack

gitblog_01164的博客 684

pscad IEEE标准系统搭建说明

pscad IEEE标准系统搭建说明,包含典型的IEEE 9节点、14节点、30节点、39节点和118节点系统。内含标准测试系统的原始数据和潮流结果。

Python-Socket编程(读书笔记)

前言:打好基础,加油!!!,给大家安利,《Python核心编程》这本书真的不错,小白不要看,适合有一定基础后再看!!!强推!!!我这个是个简单的读书笔记,目的只是为了让自己养成一种记录的习惯,毕竟咋也只是刚刚开始,没那么多自己能写的东西,希望通过这种方式督促自己的学习; 文章目录socket基本用法关于listen(n)内置方法一个简单的例子SocketServer 模块SocketServer 模块类创建 SocketServer TCP 服务端创建 SocketServer TCP 客户端Twisted

Y4tacker的博客 1万+

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

android 蓝牙通讯demo

android 下蓝牙通讯demo,实现了发现蓝牙,使能蓝牙,通过蓝牙发送消息。

socket

socket—–套接字基础创建socketimport socket tcpsock = socket.socket(socket.AF_INET,socket.SOCK_STREM)#创建Tcp/Ip套接字 udpsock = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)#创建UDp/Ip套接字内置方法 名称 描述 服务器套接字方法

小白 681

37. socketserver模块

SocketServer 是标准库中的一个高级模块,它的目标是简化很多样板代码,它们是创建网络客户端和服务器所必须的代码。这个模块中有为你创建的各种各样的类。

flurry_heart的博客 582

在浏览器中创建一个多人海盗射击游戏:

制作多人游戏具有挑战性,原因有以下几个:托管成本昂贵,设计棘手且难以实施。 通过本教程,我希望解决最后一个障碍。 这是针对那些知道如何制作游戏并熟悉JavaScript但从未制作过在线多人游戏的开发人员的。 完成后,您应该很容易在任何游戏中实现基本的网络组件,并能够在此基础上进行构建! 这是我们将要构建的: 您可以在此处尝试游戏的实时版本 ! W或上移至鼠标并单击拍摄。 (如果没有...

代码教主 647

ReactPHP Socket v3新特性详解:为什么它是构建现代网络应用的首选

ReactPHP Socket v3作为ReactPHP生态系统的核心组件,为开发者提供了异步、流式的TCP/IP和安全TLS socket服务端与客户端连接解决方案。本文将深入解析其最新版本带来的革命性改进,帮助你理解为什么它成为构建高性能网络应用的必备工具。 ## 🌟 核心架构升级:SocketServer与Connector的现代化重构 ReactPHP Socket v3最显著的变化

gitblog_00481的博客 401

i.MX6ULL嵌入式Linux网络Socket编程实战:TCP/UDP实现与交叉编译部署

网络Socket编程是构建现代分布式系统和物联网应用的基础技术,它通过操作系统提供的套接字接口,实现了不同主机间进程的通信。其核心原理在于利用IP地址和端口号唯一标识网络端点,并通过TCP或UDP协议在传输层建立可靠或高效的数据通道。这项技术的价值在于为上层应用提供了统一的网络抽象,使得开发者能够专注于业务逻辑,而无需处理底层网络硬件的复杂性。在嵌入式Linux开发领域,尤其是在物联网网关、智能硬件和工业控制等场景中,稳定高效的网络通信能力是设备互联与数据交互的关键。本文聚焦于在NXP i.MX6ULL这一

weixin_34387468的博客 426

Python 网络编程进阶:使用 SocketServer 模块构建 TCP 服务器与客户端

模块提供了一组类,用于简化网络服务器和客户端的开发。类名说明TCPServerTCP 协议服务器类UDPServerUDP 协议服务器类用于处理流式协议(如 TCP)的请求处理器基类用于处理数据报协议(如 UDP)的请求处理器基类这些类为开发者提供了清晰的接口和统一的调用方式,使得构建服务端程序变得简单而高效。简化网络编程:隐藏了底层 socket 编程的复杂细节。支持面向对象:通过类继承方式定义处理逻辑,提升代码组织能力。事件驱动架构:适合处理并发请求,易于扩展。

钢铁男儿 1113

网络编程核心实践:从Echo Server理解Socket、并发模型与调试工具

网络编程是构建分布式系统和网络应用的基础,其核心在于理解Socket通信机制。Socket作为应用层与TCP/IP协议族通信的中间软件抽象层,提供了进程间网络通信的端点。通过Socket编程,开发者可以实现在不同主机或同一主机上的进程间数据传输。其技术价值在于屏蔽了底层网络协议的复杂性,让开发者能够专注于应用逻辑。在网络调试、协议测试和学习网络I/O模型等应用场景中,一个经典且极简的实现是Echo Server(回声服务器)。它通过原样返回接收到的数据,为理解TCP/UDP协议差异、阻塞/非阻塞I/O、以及

weixin_30435261的博客 170
上一篇: Jbuild5的中文Help
下一篇: 编程老手与高手的误区
java169
博客等级 码龄19年 27粉丝 2568原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值