[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 ...
随机推荐
- 国外经典设计:12个漂亮的移动APP网站案例
优秀的移动应用程序网站是设计灵感的重要来源.从美丽的图像,合理的使用空白到排版和颜色的使用,似乎设计师都加倍努力以创造一些美好和独特的设计来推广自己的应用程序. 因此,在这篇文章中,我们已经聚集了13 ...
- Python十六进制与字符串的转换
电脑上装了Python2.7和3.3两个版本,平时运行程序包括在Eclipse里面调试都会使用2.7,但是由于某些原因在cmd命令行中输入python得到的解释器则是3.3, 一直没对此做处理,因为这 ...
- 智者当借力而行, 借助Autodesk应用程序商店实现名利双收
有没有注意到这个"精选应用"菜单?有没有想过这个菜单下的应用是从哪里来的?你的应用也可以出现在这里哦~ 如果你还不知道,Autodesk在几年前就发布了Autodesk应用程序商店 ...
- 转 java中static{}语句块详解
原文地址:http://blog.csdn.net/lubiaopan/article/details/4802430 感谢原作者! static{}(即static块),会在类被加载的时候执 ...
- 高仿精仿手机版QQ空间应用源码
说明:本次QQ空间更新了以前非常基础的代码 更新内容一 更新了登陆界面二 增加了输入时密码时和登陆成功后播放音频的效果三 增加了导航条渐隐的效果(和真实QQ空间的导航条一样,首先透明,当tablev ...
- android support的作用及其常见错误的解决
*:first-child { margin-top: 0 !important; } body>*:last-child { margin-bottom: 0 !important; } /* ...
- sql 如果关联表 没有值 设置 默认值
SELECT *FROM ( SELECT t.task_name, t.status AS task_status, coalesce( r.task_ref_id, 999 ) AS task_ ...
- MVC模式与三层架构和表示层
1.MVC模式 - Model-View-Controller - 模型-视图-控制器 - Model(模型) > 模型分为业务模型,和数据模型 ...
- php鼠标滚动加载
http://www.thinkphp.cn/extend/772.html 滚动距离js判断 i = 1; //设置当前页数 $(function() { var totalpage = 6; // ...
- 关于tempdb的一些注意事项
由于数据库的文件的位置对于I/O性能如此重要,以至于在创建主数据文件的文职时,需要考虑tempdb性能对系统性的影响,因为它是最动态的数据库,速度还需要最快. 组成:有主数据文件和日志文件组成.从sq ...