- 1、本文档共144页,可阅读全部内容。
- 2、有哪些信誉好的足球投注网站(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
南开软院2012网络课程课件
Client/server socket interaction: TCP wait for incoming connection request connectionSocket = welcomeSocket.accept() create socket, port=x, for incoming request: welcomeSocket = ServerSocket() create socket, connect to hostid, port=x clientSocket = Socket() close connectionSocket read reply from clientSocket close clientSocket Server (running on hostid) Client send request using clientSocket read request from connectionSocket write reply to connectionSocket TCP connection setup Application 2-* Client process client TCP socket Stream jargon stream is a sequence of characters that flow into or out of a process. input stream is attached to some input source for the process, e.g., keyboard or socket. output stream is attached to an output source, e.g., monitor or socket. Application 2-* Socket programming with TCP Example client-server app: 1) client reads line from standard input (inFromUser stream) , sends to server via socket (outToServer stream) 2) server reads line from socket 3) server converts line to uppercase, sends back to client 4) client reads, prints modified line from socket (inFromServer stream) Application 2-* Example: Java client (TCP) import java.io.*; import .*; class TCPClient { public static void main(String argv[]) throws Exception { String sentence; String modifiedSentence; BufferedReader inFromUser = new BufferedReader(new InputStreamReader(System.in)); Socket clientSocket = new Socket(hostname, 6789); DataOutputStream outToServer = new DataOutputStream(clientSocket.getOutputStream()); create input stream create clientSocket object of type Socket, connect to server create output stream attached to socket Application 2-* This package defines Socket() and ServerSocket() classes server port # server name, e.g., Example: Java client (TCP), cont. BufferedReader inFromServer = new BufferedReader(new InputStreamReader(c
您可能关注的文档
最近下载
- 人教PEP版六年级上册Unit 5 What does he do 单元整体教学设计.pdf
- 2021年新生儿感染:抗菌药物预防性与治疗性使用指南解读(全文).pdf
- 《数字图像处理教程》试题库.pdf VIP
- 学校意识形态工作计划.pdf
- 战略模拟软件CESIM全攻略(课堂PPT).ppt
- 中国碳交易政策对可持续经济福利的影响.pptx VIP
- 反三违(典型“三违”)行为清单.docx
- (高清版)B-T 3836.1-2021 爆炸性环境 第1部分:设备 通用要求.pdf VIP
- 人教版高一化学必修一知识点梳理.docx
- 人教pep版英语三年级上册阅读理解专项复习试卷测试题(含答案).doc
文档评论(0)