[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 ...
随机推荐
- Quill – 可以灵活自定义的开源的富文本编辑器
Quill 的建立是为了解决现有的所见即所得(WYSIWYG)的编辑器本身就是所见即所得(指不能再扩张)的问题.如果编辑器不正是你想要的方式,这是很难或不可能对其进行自定义以满足您的需求. Quill ...
- Apache 配置屏蔽某些请求头
Apache配置文件代码.xwamp:Windows下搭建Apache + PHP + MySQL环境 <Location /> SetEnvIfNoCase User-Agent &qu ...
- JavaScript学习笔记-面向对象的模块化编程
面向对象的模块化编程 模块是一个独立的JS文件,模块文件可以包含一个类定义.一组相关的类.一个实用函数库.一些待执行的代码 模块化的目标:支持大规模的程序开发,处理分散源代码的组装,并能让代码正确执行 ...
- BT5 & Kali Linux 网卡选择
[需要注意的几点]: 芯片类型 知否支持外接天线 网卡固件版本 支持的无线协议 网卡功率 BT5/Kali RC3支持网卡: RTL8187, R8187 (Realtek) 功率高.兼容性好 Ra ...
- 解决IIS进程回收后第一次访问慢的问题
IIS 有一种机制,默认会在IIS空闲一定时间段后,将应用程序池进行回收,这个时间段在IIS6中默认是20分钟,在IIS7中默认是1740分钟.两个配置都不合理,都会导致当应用程序池被回收后,第一次访 ...
- oracle中Window和Window Group
参考文献: http://www.5ienet.com/note/html/scheduler/oracle-scheduler-using-window.shtml window概念 此Window ...
- WCF分分钟入门
近来学习wcf,总结了一下入门的经验,小白的入门篇,也方便以后复习,省的去查质料. 第一步:创建wcf程序,程序初始化有一个接口和一个实现类写个简单的返回方法就可以了: 第二步:创建一个宿主,也就是服 ...
- iOS 开发之路(登陆验证调用WebService)二
swift3.0下使用Alamofire调用Webservice遇到的一些问题以及解决方案. 首先是针对没有证书的https下的接口处理问题(ps:不推荐在正式版本中使用),manager.reque ...
- 关于学习YYKit的记录
<1>遇到的问题 <1>使用@[].mutableCopy创建可变数组 代码出处:YYKitDemo-> YYRootViewController 源代码:self.ti ...
- GCD中的dispatch_barrier_async函数的使用(栅栏函数)
<一>什么是dispatch_barrier_async函数 毫无疑问,dispatch_barrier_async函数的作用与barrier的意思相同,在进程管理中起到一个栅栏的作用,它 ...