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; […]
Tag: sockets
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 […]
05 | Reading and writing with sockets: Let’s start communicating
In the previous chapters, we talked about socket-related knowledge, including socket format, socket creation, and TCP connection establishment. In this lecture, I will talk about how to use the created socket to send and receive data. The fundamental purpose of connection establishment is to send and receive data. Take our common online shopping scenarios as […]
03丨Sockets and addresses: Understand them like phones and phone numbers
In network programming, we often mention the word socket. Its Chinese translation is socket, and sometimes it is also called a socket. The original meaning of the English word socket is “socket” and “slot”. In network programming, its meaning is that the network connection and data sending and receiving can be quickly completed through socket […]
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 […]
lv7 Embedded Development-Network Programming Development 13 UNIX Domain Sockets
Table of Contents 1 UNIX domain streaming socket 2 UNIX domain datagram socket 1 UNIX domain streaming socket UNIX domain stream socket is a mechanism for communication between processes on the same host. It does not rely on the network protocol stack, but uses the file system as the basis for communication. UNIX domain streaming […]
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) { […]