select monitors on stdout and sockets

The content of selectServerInTCPIPbook.c is as follows: #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include <arpa/inet.h> #include <sys/socket.h> #include <sys/time.h> #include <sys/select.h> #defineBUF_SIZE 100 void error_handling(char *buf); int main(int argc, char *argv[]) {<!– –> int serv_sock, clnt_sock; struct sockaddr_in serv_adr, clnt_adr; struct timeval timeout; fd_set reads, cpy_reads; socklen_t adr_sz; int fd_max, str_len, fd_num, i; […]

Network Programming Sockets (3) – Protocol Customization | Serialization and Deserialization

Article directory 1. Understand “agreement” 1. The concept of agreement 2.Transmission of structured data 3. Serialization and deserialization 2. Online calculator 1. Server 2.Protocol customization (1) Correct understanding of network sending and reading (2) Issues with protocol customization 3.Client 4.Code 3. Json implements serialization and deserialization 1. Brief introduction 2.Use 1. Understanding “agreement” 1. The […]

03.UDP sockets and raw sockets

UDP socket Note that in UDP sockets, recvfrom and sendto are used API: recvfrom: Receive packets and store source address (UDP) Function prototype: int WSAAPI recvfrom( [in] SOCKET s, [out] char *buf, [in] int len, [in] int flags, [out] sockaddr *from, [in, out, optional] int *fromlen ); parameter: s: descriptor identifying the bound socket buf: […]

07 | What? And local sockets?

In the previous article, we talked about UDP. Many students know TCP and UDP, but do not know much about local sockets. In fact, local sockets are an implementation of IPC, which is local inter-process communication. In addition to local sockets, other technologies such as pipes and shared message queues are also common methods for […]

Use boost to encapsulate a websocketserver class

Based on the modifications made on the boost official website case, the implementation of the following specific functions should be based on the specific application scenarios. boost version:1.77 Function: websocket server side, able to handle multiple clients and obtain the url path of their clients Websocket.h #pragma once #include <iostream> #include <unordered_set> #include <boost/beast.hpp> #include […]

JavaEE-Network Programming Sockets (UDP/TCP)

Write a simple UDP client server process below Idea: For the server side: read the request and parse it –> make a response based on the parsed request (here is an echo,) –> write the response back to the client For the client: Read user input from the console –> Read user input from the […]

Use sockets to simulate information communication

1. Server import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.net.ServerSocket; import java.net.Socket; import java.util.Scanner; public class Server { private static Socket socket; public static void main(String[] args) { try { System.out.println(“Socket server starts running…”); ServerSocket serverSocket = new ServerSocket(9999); while (true) { socket = serverSocket.accept(); new Thread(new Server_send(socket)).start(); new Thread(new Server_listen(socket)).start(); } } catch (Exception e) { […]