Howto

  1. Create folders if not exist.

    In your hexo root.

    1
    mkdir -p source/downloads/code
  2. Include your source code in your post

    1
    {% include_code base_socket_client lang:python base_socket_client.py %}

Result

base_socket_client.pyview raw
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# @Date : 2018-07-15 12:55:35
# @Author : Simon (simon.xie@codewalker.meg)
# @Link : http://www.codewalker.me
# @Version : 1.0.0

import socket

def Main():
host = '127.0.0.1'
port = 5000

mySocket = socket.socket()
mySocket.connect((host,port))

message = input(" -> ")

while message != 'q':
mySocket.send(message.encode())
data = mySocket.recv(1024).decode()

print ('Received from server: ' + data)

message = input(" -> ")

mySocket.close()

if __name__ == '__main__':
Main()

print('xxxx')