使用socket實現簡單地http伺服器

2021-10-08 17:57:04 字數 980 閱讀 9235

本文使用ubuntu虛擬機器作為伺服器端

任意瀏覽器作為訪問瀏覽器

# 標識響應瀏覽器,不會再瀏覽器中顯示

response +=

"\r\n"

# 換行

response +=

"hello,world"

# 瀏覽器中輸出的結果

new_socket.send(response.encode(

"utf-8"))

new_socket.close(

)def

main()

:# 建立套接字

tcp_server_socket = socket.socket(socket.af_inet, socket.sock_stream)

# 繫結『伺服器』 ip和埠

tcp_server_socket.bind((""

,7890))

# 建立監聽

tcp_server_socket.listen(

128)

while

true

:# 等待客戶端請求

new_socket, client_addr = tcp_server_socket.accept(

)# 服務客服端

service_client(new_socket)

tcp_server_socket.close(

)if __name__ ==

'__main__'

: main(

)

使用註解簡單地實現ORM框架

orm 物件關係對映 簡而言之,實體類與資料庫表字段的一一對應 我們要做的工作 使用註解來實現實體類與表的對映,並且使用反射技術生成sql語句 1 定義表名的註解 target elementtype.type retention retentionpolicy.runtime public int...

WPF使用socket實現簡單聊天軟體

公司網路限制不能傳檔案,先貼部分 控制項新增到介面就行,介面隨意布局 專案結構 1.解決方案 1.1.client 1.2.server client window x class csharpsocketexample.mainwindow xmlns xmlns x title mainwind...

使用vs簡單實現socket網路通訊

最近一直在學習.net,剛把winform基礎學習完,這次算是乙個學習小結,覺得這個socket的蠻有意思的,就認真自己就完成了一遍,能簡單的傳送訊息,傳送檔案。窗體控制項我就不一一說明了,下面直接上 using system using system.collections using syste...