[Top-Down Approach]My First C/S Program [Python]
These days I was learning from Computer Networking --A Top-Down Approach by Kurose Ross.
I modified the C/S model socket program in Python in Chapter 2.
Here is the program's source code.
#!/usr/bin/python2.7
# UDP - Client
from socket import *
serverName = '192.168.1.105'
serverPort = 12000
clientSocket = socket(AF_INET, SOCK_DGRAM)
while 1:
message = raw_input('my reply:')
clientSocket.sendto(message, (serverName, serverPort))
modifiedMessage, serverAddress = clientSocket.recvfrom(2048)
print 'his reply: ' + modifiedMessage
clientSocket.close()
#!/usr/bin/python2.7
# UDP - Server
from socket import *
serverPort = 12000
serverSocket = socket(AF_INET, SOCK_DGRAM)
serverSocket.bind(('', serverPort))
print 'The server is ready to receive'
while 1:
message, clientAddress = serverSocket.recvfrom(2048)
print message + str(clientAddress)
mymsg = raw_input("my reply:")
serverSocket.sendto(mymsg, clientAddress)
#!/usr/bin/python2.7
# TCP - Client
from socket import *
serverName = '192.168.1.105'
serverPort = 12000
clientSocket = socket(AF_INET, SOCK_STREAM)
while True:
clientSocket.connect((serverName, serverPort))
sentence = raw_input('input sentence: ')
clientSocket.send(sentence)
hisReply = clientSocket.recv(1024)
print 'From Server:', hisReply
clientSocket.close()
#!/usr/bin/python2.7
# TCP - Server
from socket import *
serverPort = 12000
serverSocket = socket(AF_INET, SOCK_STREAM)
serverSocket.bind(('', serverPort))
serverSocket.listen(3)
print 'The server is ready to receive'
while True:
connectionSocket, addr = serverSocket.accept()
sentence = connectionSocket.recv(1024)
print sentence + str(addr)
myreply = raw_input('input sentence:')
connectionSocket.send(myreply)
connectionSocket.close()
Bingo!
[Top-Down Approach]My First C/S Program [Python]的更多相关文章
- Computer Networking: A Top Down Approach
目录 Chapter 1: Computer Networks and the Internet 1. What is the Internet? 2. The Network Edge 3. The ...
- python调用top命令获得CPU利用率
1.python调用top命令获得CPU利用率 思路:通过python调用top命令获取cpu使用率 #python2代码 [root@zdops-server script]# cat cpu_lo ...
- (转) [it-ebooks]电子书列表
[it-ebooks]电子书列表 [2014]: Learning Objective-C by Developing iPhone Games || Leverage Xcode and Obj ...
- Python框架、库以及软件资源汇总
转自:http://developer.51cto.com/art/201507/483510.htm 很多来自世界各地的程序员不求回报的写代码为别人造轮子.贡献代码.开发框架.开放源代码使得分散在世 ...
- Machine and Deep Learning with Python
Machine and Deep Learning with Python Education Tutorials and courses Supervised learning superstiti ...
- C 和 C++的 不同
转自: http://studytipsandtricks.blogspot.com/2012/05/15-most-important-differences-between-c.html Basi ...
- Code Complete阅读笔记(三)
2015-05-26 628 Code-Tuning Techniques ——Even though a particular technique generally represen ...
- Cracking the coding interview--问题与解答
http://www.hawstein.com/posts/ctci-solutions-contents.html 作者:Hawstein出处:http://hawstein.com/posts/c ...
- 04 Effective Go 高效的go语言 重点内容
Effective Go 高效的go语言 Introduction 介绍 Examples 例子 Formatting 格式 Commentary 评论 Names 名字 Package names ...
随机推荐
- Slideout.js – 触摸滑出式 Web App 导航菜单
Slideout.js 是为您的移动 Web 应用开发的触摸滑出式的导航菜单.它没有依赖,自由搭配简单的标记,支持原生的滚动,您可以轻松地定制它.它支持不同的 CSS3 转换和过渡.最重要的是,它只是 ...
- AngularJS 学习之路(1)
AngularJS 是一个 JS 框架,适用于以数据操作为主的 SPA (Single Page Application)应用. 不再是 "先查找元素在操作元素",所有操作都以 & ...
- javascript 对象初探(二)--- 返回对象的函数
除了使用new操作符调用构造函数以外,我们也可以抛开new操作符,只用一般函数来创建对象,这样就能执行某些预备工作,并已对象为返回值的函数.. function her(){ return { nam ...
- sharepoint 2013 持续爬网
能否对所有类型的内容源都使用连续爬网?不能.连续爬网仅适用于 SharePoint 型内容源.所有其他类型的内容源将继续选择增量爬网和完全爬网. 使用连续爬网是否会给存储库增加额外负载?连续爬网的资源 ...
- Emacs学习心得之 基础操作
作者:枫雪庭 出处:http://www.cnblogs.com/FengXueTing-px/ 欢迎转载 Emacs学习心得之 基础操作 1.前言与学习计划2.Emacs基础操作 一. 前言与学习计 ...
- 如何编写Vault插件扩展Vault Explorer的功能
今天练习了一下Vault Explorer的扩展程序,基本上是Vault SDK中的HelloWord示例程序.如果你刚刚开始接触Vault的二次开发,希望对你有帮助. 开始之前,你需要安装Vault ...
- 奇葩问题:This file could not be checked in because the original version of the file on the server was moved or deleted. A new version of this file has been saved to the server, but your check-in comments were not saved
"This file could not be checked in because the original version of the file on the server was m ...
- react native与现有的应用程序集成
(1)通过cocopods 集成 ,以下内容 参考 http://wiki.jikexueyuan.com/project/react-native/integration-existing.html ...
- 3D Touch介绍:电子秤App与快捷操作
随着iPhone6s与6s plus的到来,苹果给我们展现了一种全新的交互方式:重按手势.你可能知道,这个特性已经在Apple Watch和MacBook上推出了,不过那时叫Force Touch,就 ...
- Adobe Flash player 10 提示:Error#2044:未处理的IOErrorEvent. text=Error#2036:加载未完成 的解决方法
在“我的电脑”上单击鼠标右键,选择管理,在管理窗口的左栏中打开“服务和应用程序”,点击“服务”,在右边窗口中双击打开名称为“Smart Card”的服务,“常规”->“启动类型”选为自动,“登录 ...