Python socket for UNIX socket and dash string operation

Source: Internet
Author: User

Python socket library can implement TCP and UDP, UNIX sockets in Linux is also possible, some programs in interprocess communication is the use of UNIX sockets, if we want to view its communication information to debug, you can use Python to forge its interface, Get content

Reference: https://docs.python.org/2/library/socket.html



import socketimport os if __name__ ==  ' _ _main__ ':          sock = socket.socket (Socket.AF_UNIX,  socket. SOCK_STREAM)       if os.path.exists ('/tmp/unix.d '):           os.unlink ('/tmp/unix.d ')       sock.bind ('/ Var/run/rrdcached.sock ')          sock.listen (5)           while True:          Connection,address = sock.accept ()               print  "data : %s"%connection.recv (1024x768)           #connection. Send ("Hello")          connection.close () 


Reference: http://www.2cto.com/os/201305/210033.html

Bash under string operations:

Support ${parameter:offset:length},${parameter:offset}

[Email protected] ~/test $ string= ' Hello '

[Email protected] ~/test $ echo ${string:1:3}

Gl.

[Email protected] ~/test $ echo ${string:1}

Ello

[Email protected] ~/test $ echo $

/bin/bash


Dash: Not supported, workaround: Use expr or cut external commands instead

$ String= ' Hello '

$ expr substr "$string" 2 3

Gl.

$ echo "$string" | Cut-c2-4

Gl.

$ expr substr "$string" 2 "${#string}"

Ello

$ echo "$string" | cut-c2-

Ello

$ echo $

Dash

$


This article is from the "Danielqu" blog, make sure to keep this source http://qujunorz.blog.51cto.com/6378776/1942404

Python socket for UNIX socket and dash string operation

Related Article

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.