Regular Expression

1 Preview

  • Why do we learn Regular Expression?

  1. String manipulation is one of the most common programming work.

  2. It is very difficult to search and position strings with complicated logic.

  3. As a result, RE technique was developed and has been used for decades.

  • Definition

Regular Expression is a high-level matching mode; whose nature is a string that composed by a series of characters and particular symbols.

  • Principles

We can describe some string rules by combine the normal characters and the characters which has special meaning. The rules can stand for repeating, positions, .etc; which can be used for expressing and thus matching those specific string.

  • Goals for learning RE

  1. Be able to proficiently handle the MetaCharacters.

  2. Be able to read and edit the common REs.

  3. Be able to proficiently use the re module in Python.

程序框架

服务器端

  • server_main.py 服务器主程序,分响应者和巡逻者两个进程。 响应者负责接收客户端传输的全部数据,及时做出应答。 巡逻者负责监视用户的在线状态。
  • server_database.py 数据库管理者,负责存取数据库。
  • server_config.py 服务器接口配置

 

客户端

  • client_main.py 客户端主程序,打印菜单,接收用户输入。

进入聊天室后程序分为三个进程,分别是:

连接者:每秒告知服务端响应者客户端的连接状态。

发送者:负责告知服务端响应者用户的聊天信息。

接收者:负责接受服务端响应者发来的信息。

  • client_comm.py 应用层通讯协议指令工厂
  • client_udp.py 客户端与服务器的连接层,提供发送和接听方法
  • client_config.py 客户端配置文件,包括服务器地址和客户端端口

 

https://github.com/jarork/chatroom/tree/master