1. Socket programming
Socket types include:
--TCP socket and UDP socket.
- The General Customer service Area mode.
--raw socket
- Can be used for sniffing and injecting
2. C/S mode
c/S (client/server, client/server) mode, also known as C/s structure, is a model that grew up in the the late 1980s and is a kind of software system architecture. The key of C/s structure lies in the distribution of functions, some functions are performed on the front end machine (i.e. client), and some functions are placed on the backend machine (i.e. server).
3.python C/S programming
Server Section Code:
#!/usr/bin/env python# _*_ Coding:utf-8 _*_ImportSocketTcpsock =Socket.Socket(Socket. Af_inet,Socket. SOCK_STREAM) Tcpsock.Bind(("0.0.0.0",8080)) Tcpsock.Listen(5)Print ' Waiting for client connections ... '(Client, (ip,sock)) = Tcpsock.Accept()Print ' Set up a connection, the other IP is: 'IpPrint ' Start receiving data ... 'data =' Start ' whileLen (data): data = client.recv(2048)Print ' received data: ', data client.Send(' return data: '+data)Print ' Close connection ... 'Client.Close()Print ' Close service ... 'Tcpsock.Close()
Run the server-side Python program and test it with a command:
nc192.168.1.958080
Server response:
Client test:
4. Options for the client
- Processed sequentially
- Multi-Threaded Server
- Multi-Process Server
- Non-blocking mode socket (using Select)
Python c/S mode BASIC programming for network security