In networking, BSD socket programming is the most basic. But when perl is getting started, the biggest headache is how to start and how to Step by step. The best prescription is Example. A complete piece of code that can run (working) is far more profound than the boring manual.
The following sections describe Socket and IO: Server/client written by Socket, which can implement the simplest but most basic tasks, including a forking/accept model. You can directly copy the code and then modify it t
Python socket stream redirection instance summary, python redirection
Redirects a socket stream to a standard input or output stream.
#! /Usr/bin/env python3 "test socket-stream redirection mode" import sys, OS, timefrom multiprocessing import Processfrom socket import * def initListenerSocket (port = 50008, host = ''):" initialize the socket used by the caller to listen for connection in server mode "" sock = socket () try:
On the networking side, the most basic is BSD socket programming, but often when Perl is getting started in this area, the biggest headache is undoubtedly how to start, how to step by step. The best remedy is example, a complete code that can be run (working), which is more deeply felt by practice than by the boring manual.
Here are a few paragraphs of server/client written using sockets and io::socket to achieve the simplest but most basic tasks, including a forking/accept model. You can copy
Asmlinkage long sys_socketcall (INT call, unsigned long _ User * ARGs );
{Unsigned long a [6];/* Obtain information from the user space. This function is SMP secure */If (copy_from_user (A, argS, nargs [Call])Return-efault;
Switch (CALL ){Case sys_socket:Err = sys_socket (A [0], a [1], a [2]);Break;Case sys_bind:Err = sys_bind (A [0], (struct sockaddr _ User *) A [1], a [2]);Break;Case sys_connect:Err = sys_connect (A [0], (struct sockaddr _ User *) A [1], a [2]);Break;
....}}
/** The following
1. Background:In front of the listen backlog to the full connection and the impact of semi-connection, this article will be from the kernel source (kernel 2.6.32) Simple understanding of the service side of the three-time handshake and the backlog in the middle of the role.2. Three-time handshake:2.1 Service-Side monitoring:After System_call, through the FD number to obtain the corresponding socket, and the backlog is limited to the maximum value, and then into the Inet_listen function for proce
data can be shared without a thread. Therefore, the parent process can only pass the queue to the child process by passing parameters.
Import multiprocessingimport threadingdef foo (q): q. put ([12, 'Hello', True]) if _ name _ = '_ main _': q = multiprocessing. queue () # create a process Queue # create a sub-thread p = multiprocessing. process (target = foo, args = (q,) # pass the queue object to the parent Process p by passing parameters. start () print (q. get ())
1.2 Pipelines
The socket we
I have previously written about HTTP-based communication at the network transmission layer. Now the project needs to implement the TCP/IP communication protocol. I searched through the network. Someone has already written a public class library asyncsocket, the following describes how to use asyncsocket.
Asyncsocket official documentation: http://code.google.com/p/cocoaasyncsocket/
The usage is as follows:
1. Create a project.
2. Add asyncsocket to the project.
3. Add cfnetwork. Framework to the
Recently, When I port the RTSP library to wince, I cannot read the data. To solve the problem, I wrote a small RTSP client protocol learning program to implement basic session protocols, options, describe, setup, play and other protocols to save the read data to the file. The program code is pasted below, which can run on ce and PC. For your sharing.
# Ifdef _ win32_wce# Include "stdafx. H"# Endif
# Ifndef _ win32_wce# Define win32_lean_and_mean# Endif
# Include # Include
# Include
# Include
event shall the copyright owner or contributors be liable for any direct, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, or consequential damages (INCLUDING, but not limited, procurement of substitute goods or services; loss of use, DATA, or profits; or business interruption) however caused and on any theory of liability, whether in contract, strict liability, or tort (including negligence or otherwise) arising in any way out of the use of this software, even if advised of the possibility of such da
Kernel version: 2.6.34
This section is about how the socket was created and accessed by the kernel protocol stack, focusing only on two issues: sock when the kernel table was inserted, and how sock was accessed by the kernel. For the core of the sock insert, lookup functions are given a flowchart.
Sock How to insert
;sk_prot->disconnect (sk,flags) function is eventually called in this statement, Sk_prot is a member of the SK object, pointing to a pointer table that contains a pointer to the number function. The specifics of where these functions are performed depend on the protocol type, which includes TCP, UDP, and so on. So the Sk->sk_prot_disconnect (Sk,flag) statement is ultimately the function called the Udp_disconnect (struct sock *sk,int flag):>And in the
)){G_csfor_ptrary_sockclient.unlock ();Return false;}}}G_csfor_ptrary_sockclient.unlock ();Return true;}
When a new client is connected to the server, the server sends the client information (IP address and port number) to other clients.
//// Performer: Client// A new client B is logged on. I (Client A) connected to the server port srv_tcp_hole_port and applied to establish a direct TCP connection with client B.//Bool handle_newuserlogin (csocket mainsock, t_newuserloginpkt * pnewuserloginpkt)
Create a MySQL user and a MySQL user groupGroupadd MySQLUseradd-G MySQL
Install MySQL using the source package
1.download the mysqlinstallation package (.tar.gz) from mysql's official website)Http://dev.mysql.com/get/Downloads/MySQL-5.0/mysql-5.0.51a.tar.gz/from/pick
2.set mysql-5.0.51a.tar.gz to the directory/home/mahaibo after download.
Install MySql in the directory:/home/mahaibo/install/MySQLDirectory of the mysql. Sock file called by MySQL:/home/
NANOMSG Experiment--pubsubThe Publish subscription model is a common feature provided by many message middleware. The message mechanism enables the message publisher and the message to receive (consume) peopleTo decouple. PubSub mode is also one of the message models directly supported by NANOMSG, so through the PubSub model experiment,At the same time, we also have a general understanding of the basic usage of nanomsg.Service Side
The code is as follows
Copy Code
#in
socket is actually a huge sock structure, it is associated with the network protocol layer at the following layer, shielding the differences between different network protocols. Only the data is presented to the application layer (presented through the system call interface ).
3. The network protocol implementation layer is undoubtedly the core of the entire protocol stack. This layer mainly implements various network protocols, including IP, ICMP, A
implies, of course, is provided by the application, for the transmission of data semantic interpretation of the "Man-machine Interface" layer, such as http,smtp,ftp, and so on, in fact, the application layer is not what people eventually see that layer, the top layer should be "interpretation layer", Responsible for the final presentation of the data in various form items.Linux Network protocol stack structure1, the system calls the interface layer, essentially a user-space application-oriented
process sleep until the system wakes up when the resource is available and traverses the previously monitored array. Each traversal is linear.
2. select echo serverThe select statement involves the knowledge of system calls and operating systems. Therefore, it is boring to simply understand the principle. It is better to use code to demonstrate it. Using the select module of python, you can easily write the following echo server:
Import selectimport socketimport sysHOST = 'localhost' PORT = 50
() system to call a new socket, it needs to pass the socket address family identifier, socket type and Protocol. Its function is defined in net/socket. C:
Asmlinkagelong sys_socket (INT family, int type, int Protocol)
{
Int retval;
Struct socket * sock;
Retval = sock_create (family, type, protocol, sock );
If (retval
Goto out;
Retval = sock_map_fd (sock );
I
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.