1 / 7
文档名称:

基于tcp和udp的socket编程.doc

格式:doc   大小:58KB   页数:7页
下载后只包含 1 个 DOC 格式的文档,没有任何的图纸或源代码,查看文件列表

如果您已付费下载过本站文档,您可以点这里二次下载

文档介绍:-
. z.
1课程设计名称
网络编程实验
2课程设计目的
1.通过基于TCP的Socket程序的编写、调试,掌握以下知识点:
1〕Socket的编程方法;
2〕基于TCPublic static void main(String argv[]) throws E*ception {
String clientSentence;
String sentenceLength;
ServerSocket welcomeSocket = new ServerSocket(6789);
while(true){
Socket connectionSocket = welcomeSocket.accept();
BufferedReader inFromClient = new BufferedReader(new InputStreamReader(connectionSocket.getInputStream()));
DataOutputStream outToClient = new DataOutputStream(connectionSocket.getOutputStream());
clientSentence = inFromClient.readLine();
-
. z.
sentenceLength = String.valueOf(clientSentence.length()) + '\n';
outToClient.writeBytes(sentenceLength);
}
}
}
编写TCPClient.java
import java.io.*;
import java.net.*;
class TCPClient {
public static void main(String argv[]) throws E*ception {
String sentence;
String sentenceLength;
BufferedReader inFromUser = new BufferedReader(new InputStreamReader(System.in));
Socket clientSocket = new Socket("DESKTOP-2PC4RS3", 6789);
DataOutputStream outToServer = new DataOutputStream(clientSocket.getOutputStream());
BufferedReader inFromServer = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
sentence = inFromUser.readLine();
outToServer.writeBytes(sentence + '\n');
sentenceLength = inFrom

分享好友

预览全文

基于tcp和udp的socket编程.doc

上传人:sdnmy78 7/31/2022 文件大小:58 KB

下载得到文件列表

基于tcp和udp的socket编程.doc

相关文档