[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 ...
随机推荐
- js的一些属性
js attribute(): setAttribute():element.setAttribute(name,balue) getAttribute():element.getAttribute( ...
- border-radius如何兼容IE
目前而言firefox,opera,chrome等主流浏览器都已经支持border-radius属性,唯独IE8以及之前. 解决办法就是在用的border-radius属性的后面加上:behavior ...
- WPS 从今以后我再也不会用了 记录一下!
一个双十一,金山忙得不亦乐乎,就往桌面上添加图标. 卸载掉你!!!!! 一些令人厌恶的动作: 1.强制弹广告. 2.强制弹新闻窗口:WPS热点:无法设置不再弹出. 3.强制自动升级.删了还会有. 4. ...
- iOS Assigning to 'id<XXXDelegate>' from incompatible type 'BViewController *__strong'
在使用代理的时候, BViewController *BVC = [[BViewController alloc]init]; self.delegate = BVC; 出现这样的警告Assignin ...
- 在内网中OWA第一次访问速度慢的问题
当网络环境为内网时,有时访问OWA站点一直卡在Office Web App 那里. 这是因为SharePoint有一个证书需要联网检索 此环境为SharePoint 2013 通过下面的三个步骤 ...
- SharePoint 向多行文本类型字段插入特殊类型链接
1.在测试列表中插入一个多行文本字段,名字叫做Content,如下图: 2.在Content字段里,添加一个Link,如下图: 3.尝试输入Notes格式的Link,如下图: 4.点击OK的时候,弹出 ...
- SharePoint如何关掉mysite. how to disable mysite creation
一个很简单的问题 center admin --> application managment -->manage service application -->user profi ...
- Swift使用注意
二.函数的可选参数 参数名:参数类型? = 默认值 // 调用的时候会发现生成了两个函数,一个带imageName,一个不带,选择不带的,调用此函数时将使用参数值nil convenience ini ...
- iOS设置文字过长时的显示格式
以label为例: //设置文字过长时的显示格式 aLabel.lineBreakMode = UILineBreakModeMiddleTruncation; //截去中间 aLabel.lineB ...
- Android四大组件之Activity一(组件的概念、Intent、监听)
前言知识补充: 什么是组件? 1.它的类必须实现特定接口或继承特定类 2.需要在配置文件中配置其全类名 3.它的对象不是通过new来创建的, 而是系统自动创建的 4.它的对象具有一定 ...