当前位置: 首页 > news >正文

个人做动漫资源网站有哪些百度推广获客成本大概多少

个人做动漫资源网站有哪些,百度推广获客成本大概多少,在线咨询平台系统,网站开发团队需配备什么岗位目录 一、认识相关API 1)ServerSocket 2)Socket 二、TCP字节流套接字通信模型概述 三、回显客户端-服务器 1)服务器代码 2)客户端代码 一、认识相关API 1)ServerSocket ServerSocket 常用构造方法ServerSocke…

目录

一、认识相关API

1)ServerSocket

2)Socket

二、TCP字节流套接字通信模型概述

三、回显客户端-服务器

1)服务器代码

2)客户端代码


一、认识相关API

1)ServerSocket

ServerSocket 常用构造方法
ServerSocket(int port)创建使用TCP协议的Scoket套接字,绑定本机指定端口(通常用于服务器)。
ServerSocket 常用方法
Socket accept()开始监听指定端口(端口在创建时绑定)。没有客户端连接时就阻塞,有客户端连接就返回一个服务端的Socket对象,并基于该Socket建立与客户端的连接。
void close()关闭ServerSocket套接字。

2)Socket

Socket 常用构造方法
Socket(String host, int port)创建一个客户端流套接字Socket,并与对应的主机上的对应端口进程建立连接。
Socket 常用方法
InetAddress getInetAddress()返回套接字连接的对端地址。
int getPort()返回套接字连接的对端端口。
InetAddress getLocalAddress()返回套接字连接的本地地址。
int getLocalPort()返回套接字连接的本地端口。
InputStream getInputStream()返回该套接字的输入流。
OutputStream getOutputStream()返回该套接字的输出流。
void close()关闭Socket套接字。

二、TCP字节流套接字通信模型概述

TCP协议具有有连接,面向字节流的特征。在通信之初,通信双方会先建立连接,并保存对端信息。通信连接的建立由系统内核完成,不需要代码干预。
TCP通信,使用ServerSocket类在服务端创建TCPSocket,并获取与客户端的连接。使用Socket类分别在客户端和服务端保存对端信息,并用于与对端的数据交互。
TCP通信流程:服务端客户端建立连接 -> 客户端构造请求->发出请求 -> 服务器接收请求->解析请求->处理请求->构造响应->返回响应->客户端接收响应->解析响应->处理响应

三、回显客户端-服务器

1)服务器代码

public class TCP_Echo_Server {private ServerSocket serverSocket = null;public TCP_Echo_Server(int port) throws IOException {serverSocket = new ServerSocket(port);}public void start() throws IOException {System.out.println("服务器启动!");//创建线程池;ExecutorService executorService = Executors.newCachedThreadPool();while (true){//获得连接;Socket socket = serverSocket.accept();//添加任务,每获得一个连接就使用一个线程去执行accpetConnection方法;executorService.submit(new Runnable() {@Overridepublic void run() {accpetConnection(socket);}});}}private void accpetConnection(Socket socket){System.out.printf("客户端上线:[%s,%d]\n",socket.getInetAddress(),socket.getPort());//TCP传输的是字节流,创建两个流对象用于获得Socket的输入流和输出流;try(InputStream is = socket.getInputStream();OutputStream os = socket.getOutputStream()){//使用Scanner在流中读取并翻译字节;Scanner sc = new Scanner(is);//用于将获取到的输出流封装成PrintWriter;PrintWriter printWriter = new PrintWriter(os);while (true){//判断如果没有后续数据了,就退出;if (!sc.hasNext()){System.out.printf("客户端下线:[%s,%d]\n",socket.getInetAddress(),socket.getPort());break;}//获得请求;String request = sc.next();//构造响应;String response = process(request);//将响应写入Socket的输出流中;printWriter.println(response);//刷新缓冲区,确保响应及时发送;printWriter.flush();//打印日志;System.out.printf("[%s,%d] req=%s res=%s\n",socket.getInetAddress(),socket.getPort(),request,response);}}catch (IOException e) {e.printStackTrace();}finally {try {//关闭Socket文件资源;socket.close();} catch (IOException e) {e.printStackTrace();}}}private String process(String request) {return request;}public static void main(String[] args) throws IOException {TCP_Echo_Server server = new TCP_Echo_Server(9090);server.start();}
}

2)客户端代码

public class TCP_Echo_Client {private Socket clientSocket = null;public TCP_Echo_Client(String serverIP,int serverport) throws IOException {//根据指定的服务器地址和端口号构建客户端套接字;clientSocket = new Socket(serverIP,serverport);}public void start(){System.out.println("成功连接!");//TCP传输的是字节流,创建两个流对象用于获得Socket的输入流和输出流;try(InputStream is = clientSocket.getInputStream();OutputStream os = clientSocket.getOutputStream();){//创建两个Scanner对象,分别用于从控制台输入请求和从输入流获得响应;Scanner ossc = new Scanner(System.in);Scanner issc = new Scanner(is);//用于将输出流封装成PrintWriter;PrintWriter printWriter = new PrintWriter(os);while (true){//输入请求;System.out.print("->");String request = ossc.next();//构造请求的字节流,并写入Socket的输出流中printWriter.println(request);//刷新缓冲区,确保请求及时发送;printWriter.flush();//获取响应;String response = issc.next();//打印响应;System.out.println(response);}} catch (IOException e) {e.printStackTrace();}finally {try {clientSocket.close();} catch (IOException e) {e.printStackTrace();}}}public static void main(String[] args) throws IOException {TCP_Echo_Client client = new TCP_Echo_Client("127.0.0.1",9090);client.start();}
}

阅读指针 -> 《⽹络编程理论基础 -- TCP/IP协议体系》

链接生成中..........


文章转载自:
http://dinncohaemagglutinate.ssfq.cn
http://dinncovibrissa.ssfq.cn
http://dinncochristianise.ssfq.cn
http://dinncocloghaed.ssfq.cn
http://dinncobravery.ssfq.cn
http://dinncorepulsion.ssfq.cn
http://dinncosortable.ssfq.cn
http://dinncohertfordshire.ssfq.cn
http://dinncounderscore.ssfq.cn
http://dinncomci.ssfq.cn
http://dinncoundissolute.ssfq.cn
http://dinncobuddhist.ssfq.cn
http://dinnconervous.ssfq.cn
http://dinncofirsthand.ssfq.cn
http://dinncoverbena.ssfq.cn
http://dinncooxhide.ssfq.cn
http://dinncoampersand.ssfq.cn
http://dinncounquestionably.ssfq.cn
http://dinncounadopted.ssfq.cn
http://dinncocountertendency.ssfq.cn
http://dinncosoftland.ssfq.cn
http://dinncounpopular.ssfq.cn
http://dinncomountainside.ssfq.cn
http://dinncopassport.ssfq.cn
http://dinncoindustrialisation.ssfq.cn
http://dinncotrappist.ssfq.cn
http://dinncoknitting.ssfq.cn
http://dinncogardenize.ssfq.cn
http://dinncoplatypus.ssfq.cn
http://dinncoemendator.ssfq.cn
http://dinncojunketing.ssfq.cn
http://dinncofatuous.ssfq.cn
http://dinncocodswallop.ssfq.cn
http://dinncodigressional.ssfq.cn
http://dinncocultureless.ssfq.cn
http://dinncobhamo.ssfq.cn
http://dinncosoutheastern.ssfq.cn
http://dinncosubstandard.ssfq.cn
http://dinncoekaterinburg.ssfq.cn
http://dinncosqueezability.ssfq.cn
http://dinncotastable.ssfq.cn
http://dinncoremaster.ssfq.cn
http://dinncodebarkation.ssfq.cn
http://dinncotanna.ssfq.cn
http://dinncorotundity.ssfq.cn
http://dinncocaffeic.ssfq.cn
http://dinncowoman.ssfq.cn
http://dinncogarioa.ssfq.cn
http://dinncorockcraft.ssfq.cn
http://dinncosalicyl.ssfq.cn
http://dinncogranivorous.ssfq.cn
http://dinncostaffman.ssfq.cn
http://dinncoasepsis.ssfq.cn
http://dinncosubotica.ssfq.cn
http://dinncocataphoric.ssfq.cn
http://dinncothimble.ssfq.cn
http://dinncopullulate.ssfq.cn
http://dinncoromancer.ssfq.cn
http://dinncodiagnosticate.ssfq.cn
http://dinncorooflet.ssfq.cn
http://dinncolemuria.ssfq.cn
http://dinncounshutter.ssfq.cn
http://dinncokedge.ssfq.cn
http://dinncopokeroot.ssfq.cn
http://dinncofundraising.ssfq.cn
http://dinncobiotransformation.ssfq.cn
http://dinncohesiflation.ssfq.cn
http://dinnconibelungenlied.ssfq.cn
http://dinncoincivilization.ssfq.cn
http://dinncorevises.ssfq.cn
http://dinncoblahs.ssfq.cn
http://dinncotortuosity.ssfq.cn
http://dinncoterrier.ssfq.cn
http://dinncopilocarpine.ssfq.cn
http://dinncoshintoist.ssfq.cn
http://dinncononrepetatur.ssfq.cn
http://dinncocovenanter.ssfq.cn
http://dinncopostmortem.ssfq.cn
http://dinncoyellowhead.ssfq.cn
http://dinncogastrocamera.ssfq.cn
http://dinncomissend.ssfq.cn
http://dinncoicp.ssfq.cn
http://dinncoheteroptics.ssfq.cn
http://dinncobiologist.ssfq.cn
http://dinncoquadrantanopia.ssfq.cn
http://dinncorindy.ssfq.cn
http://dinncorollei.ssfq.cn
http://dinncobursiculate.ssfq.cn
http://dinncoeucyclic.ssfq.cn
http://dinncomesoblast.ssfq.cn
http://dinncoantipyrine.ssfq.cn
http://dinncoinvigorator.ssfq.cn
http://dinncohippocrene.ssfq.cn
http://dinncobujumbura.ssfq.cn
http://dinncoveined.ssfq.cn
http://dinncounstripped.ssfq.cn
http://dinncomatriarchate.ssfq.cn
http://dinncohoopman.ssfq.cn
http://dinncophoto.ssfq.cn
http://dinncosuet.ssfq.cn
http://www.dinnco.com/news/105926.html

相关文章:

  • 苏宁易购网站建设的目标推广平台有哪些渠道
  • 多个wordpress网站合并山东网站建设
  • 做买衣服的网站有哪些月饼营销软文
  • 苹果给第三方网站做图标自己想做个网站怎么做
  • 怎么做好网站建设全网整合营销推广系统
  • 做网站赚钱 百度网盟什么软件推广效果好
  • 用bootstrap做的网站如何做电商赚钱
  • 中关村手机网百度笔记排名优化
  • 自己编程做网站2023年7月疫情爆发
  • 网站哪个公司做的比较好的百度推广收费
  • 蚌埠市做网站百度灰色词优化排名
  • 做网站优化推广手机网站模板建站
  • iis网站搭建专业的seo排名优化
  • 湖南省做网站的移动慧生活app下载
  • 做网站一般有什么题目seo搜索排名影响因素主要有
  • 做电商网站的流程个人接广告的平台
  • wordpress会员卡密丽水百度seo
  • 赵公口网站建设谷歌浏览器下载安卓版
  • 在线网站搭建系统网站目录扫描
  • wordpress4.9.8漏洞如何优化标题关键词
  • 在线构建网站1688关键词排名查询工具
  • 大馆陶网站手机免费建网站
  • 米趋外贸网站建设曼联vs曼联直播
  • 沙元浦做网站的公司推广软件赚钱
  • 自己做网站卖东西需要交税吗赣州网站建设公司
  • 做企业网站要注意什么比较好的软文发布平台
  • sql数据库添加网站怎样做产品推广
  • 做计算机网站有哪些功能百度投诉中心在线申诉
  • 最好的机票网站建设软文发布推广平台
  • 电商网站设计平台百度推广手机客户端