跨平台网络编程题库(解释型编程语言是如何实现跨平台的)

http://www.itjxue.com  2023-02-03 03:58  来源:未知  点击次数: 

求助网络编程题目.C++

一.概述

TCP/IP协议是一个四层协议,它由应用层、传输层、网络层和链路层构成。TCP/IP协议栈的每一层都由许多协议构成,从而构成了一个协议簇。

应用层主要包括的协议有Telnet、FTP、HTTP、SMTP/POP3和DNS等。

传输层主要包括的协议有TCP和UDP。

网络层主要包括IP和IP的附属协议。

数据链路层主要包括的协议有ARP(地址解析协议)、RARP协议、Ethernet协议等。

FTP(File Transfer Protocol)协议主要用来在网络上进行文件传输。FTP通讯除了有一个默认的端口21外,还有其他端口,同城两个端口同时进行数据传输。一个是默认的端口(通常为21),主要进行控制连接,即进行命令协议及服务器端响应码的传输。另一个非标准端口主要进行数据,上传下载文件等。

关于FTP协议和FTP命令的详细描述,参考《Visual C 网络通信编程实用案例精选》。

实现FTP协议,有两种方式,实用WinInet API和使用基本Winsock。对于一般应用,用WinInet效率要高,而且简单。也可以用Winsock来编写,这样更加灵活,但是复杂度高且需要对协议非常熟悉。

二.VC开发

在项目中,为了开发效率,使用了WinInet的方式。

FTP是MFC的WinInet支持的三个Internet功能(HTTP, gopher)之一,我们需要先创建一个CInternetSession实例和一个CFtpConnection对象就可以实现和一个 FTP服务器的通信。不需要直接创建CFtpConnection对象,而是通过调用CInternetsession::GetFtpConnection来完成这项工作。它创建CFtpConnection对象并返回一个指向该对象的指针。

要联接到FTP服务器,需要两个步骤,首先必须创建一个CInternetSession对象,用类CInternetSession创建并初始化一个或几个同时存在的Internet会话(session),并描述与代理服务器的连接(如果有必要的话),如果在程序运行期间需要保持与Internet的连接,可以创建一个CInternetsession对象作为类CWinApp的成员。

然后利用CInternetsession对象获取CFtpConnection对象。MFC中的类CFtpConnection管理我们与Internet服务器的连接,并直接操作服务器上的目录和文件。

1.Ftp连接类的信息

下面我们简要介绍连接类的信息

1.1 建立连接

CInternetsession对象

CInternetsession(LPCTSTR pstrAgent, DWORD dwConText, DWORD dwACCESSType, LPCTSTR pstrProxyName, LPCTSTR pstrProxyBypass, DWORD dwFlags);

在创建CInternetSession对象时调用这个成员函数,CInternetsession是应用程序第一个要调用的Internet函数,它将创始化内部数据结构,以备将来在应用程序中调用。如果dwFlags包含INTERNET_FLAG_ASYNC,那末从这个句柄派生的所有的句柄,在状态回调例程注册之前,都会出现异步状态。如果没有打开Internet连接,CInternetsession就会抛出一个例外,AfxThrowInternetException。

GetFtpConnection()函数

CFtpConnection* CIternetsession::GetFtpConnection(LPCTSTR pstrServer, LPCTSTR pstrUserName, LPCTSTR pstrPassword, INTERNET_PORT nPort, BOOL bPassive);

调用这个函数建立一个FTP连接,并获得一个指向CFtpConnection对象的指针,GetFtpConnection连接到一个FTP服务器,创建并返回指向CFtpConnection对象的指针,它不在服务器上进行任何操作。如果打算读写文件,必须进行分步操作。关于查找,打开和读写文件的信息需参考CFtpConnection和CFtpFileFind类。

对这个函数的调用返回一个指向CFtpConnection对象的指针。如果调用失败,检查抛出的CInternetException对象,就可以确定失败的原因。

1.2 远程目录操作

CreateDirectory()函数

BOOL CreateDirectory( LPCTSTR pstrDirName );

Return Value

Nonzero if successful; otherwise 0. If the call fails, the Windows functionGetLastError may be called to determine the cause of the error.

Parameters

pstrDirName

A pointer to a string containing the name of the directory to create.

Remarks

Call this member function to create a directory on the connected server.

Use GetCurrentDirectory to determine the current working directory for this connection to the server. Do not assume that the remote system has connected you to the root directory.

The pstrDirName parameter can be either a partially or a fully qualified filename relative to the current directory. A backslash (\) or forward slash (/) can be used as the directory separator for either name. CreateDirectory translates the directory name separators to the appropriate characters before they are used.

注意:CreateDir 在FTP服务器上创建已经存在的文件夹时会 返回FALSE,而且只能创建到当前(根)目录下

RemoveDirectory()函数

BOOL RemoveDirectory( LPCTSTR pstrDirName );

Return Value

Nonzero if successful; otherwise 0. If the call fails, the Win32 functionGetLastError may be called to determine the cause of the error.

Parameters

pstrDirName

A pointer to a string containing the directory to be removed.

Remarks

Call this member function to remove the specified directory from the connected server.

Use GetCurrentDirectory to determine the server’s current working directory. Do not assume that the remote system has connected you to the root directory.

The pstrDirName parameter can be either a partially or fully qualified filename relative to the current directory. A backslash (\) or forward slash (/) can be used as the directory separator for either name. RemoveDirectory translates the directory name separators to the appropriate characters before they are used.

注意:DeleteDir文件夹中有内容,先删除文件夹中文件,才可以删文件夹,否则返回FALSE, 删除不存在的文件夹返回FALSE

1.3 文件上传下载删除

GetFile()函数

BOOL GetFile(LPCTSTR pstrRemoteFile, LPCTSTR pstrLocalFile, BOOL bFailExists, DWORD dwAttributes, DWORD dwFlags, DWORD dwContext);

调用这个成员函数,可以从FTP服务器取得文件,并且把文件保存在本地机器上。GetFile()函数是一个比较高级的例程,它可以处理所有有关从FTP服务器读文件,以及把文件存放在本地机器上的工作。如果dwFlags为 FILE_TRANSFER_TYPE_ASCII,文件数据的传输也会把控制和格式符转化为Windows中的等阶符号。默认的传输模式是二进制模式,文件会以和服务器上相同的格式被下载。

pstrRemoteFile和 pstrLocalFile可以是相对于当前目录的部分文件名,也可以是全文件名,在这两个名字中间,都既可以用反斜杠(\)或者正斜杠(/)来作为文件名的目录分隔符,GetFile()在使用前会把目录分隔符转化为适当的字符。

可以用自己选择的值来取代dwContext默认的值,设置为上下文标识符与CFtpConnection对象的定位操作有关,这个操作由CFtpConnection中的CInternetSession对象创建。返回给CInternetsession::OnStatusCallBack的值指出了所标识操作的状态。

如果调用成功,函数的返回为非0,否则返回0,如果调用失败,可以调用Win32函数GetLastError(),确认出错的原因。

需要注意:本地路径须为绝对路径,远程路径可为相对路径,如hello/hello.zip,如果本地文件已经存在,则返回FALSE。

PutFile()函数

BOOL PutFile(LPCTSTR pstrLocalFile, LPCTSTR pstrRemoveFile ,DWORD dwFlags, DWORD dwContext);

调用这个成员函数可以把文件保存到FTP服务器。PutFile()函数是一个比较高级的例程,它可以处理有关把文件存放到服务器上的工作。只发送数据,或要严格控制文件传输的应用程序,应该调用OpenFile和 CInternet::Write。利用自己选择的值来取代dwContext默认的值,设置为上下文标识符,上下文标识符是 CInternetSession对象创建的CFtpConnection对象的特定操作有关,这个值返回给CInternetsession::OnStateCallBack,从而把操作的状态通报给它所标识的上下文。

如果调用成功,函数的返回为非0,否则返回0,如果调用失败,可以调用Win32函数GetLastError(),确认出错的原因。

主要注意:如果重复上传文件,会把服务器上的文件覆盖掉,且可以上传特定文件夹下,如hello/hello.zip

Remove()函数

BOOL Remove( LPCTSTR pstrFileName );

如果调用成功,函数的返回为非0,否则返回0,如果调用失败,可以调用Win32函数GetLastError(),确认出错的原因。

pstrFileName

需要删除的服务器上的文件名

Call this member function to delete the specified file from the connected server.

The pstrFileName parameter can be either a partially qualified filename relative to the current directory or fully qualified. A backslash (\) or forward slash (/) can be used as the directory separator for either name. The Remove function translates the directory name separators to the appropriate characters before they are used.

注意:Remove如果删除的文件不存在,则返回FALSE,支持相对路径

2. 测试实例

2.1 例一 连接到FTP站点

建立连接到的程序,它是一个单文档程序。并且连接由视图类的构造函数完成。

建立单文档程序ftp

在ftpview.h中加入包含#include afxinet.h

在ftpview.h中添加如下的成员变量

public:

CInternetSession *m_pInetsession;

CFtpConnection *m_pFtpConnection;

在ftpview.cpp中的ftpview构造函数中加入下面的代码

CFtpView::CFtpView()

{

m_pInetSession=new CInternetsession

(AfxGetAppName(),1,

PRE_CONFIG_INTERNET_ACCESS);

try

{

m_pFtpConnection=m_pInetsession-

GetFtpConnection("");

}

catch(CInternetException *pEx)

{

TCHAR szError[1024];

if(pEx-GetErrorMessage(szError,1024))

AfxMessageBox(szError);

else

AfxMessageBox("There was an exception");

pEx-Delete();

m_pFtpConnection=NULL;

}

}

在ftpview.cpp中的ftpview析构函数中加入下面的代码

CFtpView::~CFtpView()

{

if(m_pFtpConnection!=NULL)

{

m_pFtpConnection-Close();

delete m_pFtpConnection;

}

delete m_pInetsession;

}

编译并且执行程序,如果连接出现问题,将会在一个消息框中报告出错消息。

2.2 例二 发送文件到FTP文件服务器

创建一个发送文件到FTP文件服务器的程序

建立单文档程序ftpfw, 在ftpfwview.h中加入包含 #include afxinet.h

在ftpfwview.h中添加如下的成员变量

public:

bool m_bConnectionAttempted;

int m_nFileStatus;

在ftpview.cpp中的ftpview构造函数中加入下面的代码

CFtpfwView::CFtpfwView()

{

m_bConnectionAttempted=false;

}

使用ClassWizard加入新的类CFtpThread,该类派生于CWinThread 在ftpthread.h中加入如下变量

public:

static UINT PutFile(LPVOID Status);

添加新类成员函数代码

UINT CFtpThread::PutFile(LPVOID Status)

{

int *pnFileStatus;

CInternetSession *pInetsession;

CFtpConnection *pFtpConnection=NULL;

pnFileStatus=(int *)Status;

*pnFileStatus=0;

pInetsession=new CInternetsession(AfxGetAppName(),1,

PRE_CONFIG_INTERNET_ACCESS);

try

{

pFtpConnection=pInetsession-

GetFtpConnection("192.34.45.0");

}

catch(CInternetException *pEx)

{

pEx-Delete();

pFtpConnection=NULL;

*pnFileStatus=-1;

goto BallOut;

}

*pnFileStatus =1;

pFtpConnection-Remove("test.txt");

if(!pFtpConnection-PutFile

("test.txt","test.txt"))

*pnFileStatus=-2;

else

*pnFileStatus=2;

BallOut:

if(pFtpConnection!=NULL)

{

pFtpConnection-Close();

delete pFtpConnection;

}

delete pInetsession;

AfxEndThread(0);

return false;

}

编辑ftpfwview.cpp中的OnDraw()函数

void CFtpfwView::OnDraw(CDC* pDC)

{

CFtpfwDoc* pDoc = GetDocument();

ASSERT_VALID(pDoc);

if(!m_bConnectAttempted)

{

m_bConnectAttempted=TRUE;

AfxBeginThread((AFX_THREADPROC)

CFtpThread::PutFile,m_nFileStatus);

}

}

编译并且执行程序,在连接和传输的过程中,应用程序仍然可以作自己的工作,这是因为传输的过程发生在线程中。

3.封装FTPTransfer类

3.1 头文件

///////////////////////////////////////////////////////////

// FTPTransfer.h

// interface of the FTPTransfer module

// Created on: 24-July-2010

// Original author: Andrew Zhang

///////////////////////////////////////////////////////////

#ifndef _FTPTRANSFER_H_

#define _FTPTRANSFER_H_

#include afxinet.h // for ftp api functions

class FTPTransfer

{

public:

FTPTransfer();

~FTPTransfer();

BOOL Login();

void Logout();

BOOL CreateRemoteDir(LPCTSTR pstrDirName);

BOOL DeleteRemoteDir(LPCTSTR pstrDirName);

BOOL Upload(LPCTSTR pstrLocalFile, LPCTSTR pstrRemoteFile);

BOOL Download(LPCTSTR pstrRemoteFile, LPCTSTR pstrLocalFile);

BOOL DeleteRemoteFile(LPCTSTR pstrFileName);

BOOL UploadAll();

CString GetLastError();

protected:

private:

void Config();

CString m_csServer;

CString m_csUsername;

CString m_csPassword;

unsigned int m_nPort;

CInternetSession *m_pSession;

CFtpConnection *m_pConn;

static CString lastError;

public:

// 需要传输的文件夹

CStringArray m_astrAllDirName;

CString m_csLocalDir; // 本地图像所在路径,需要外界赋值。

};

#endif

3.2 设置配置项

可以配置服务器的IP,Port,用户名,密码等

配置项样例:

[FTPTransfer]

FTPServer = 192.168.29.253

Username = andrew

Password = zhang

Port = 21

;Ftp服务器的IP 账户 密码

3.3 使用说明

FTPTransfer transfer;

transfer.m_csLocalDir = url + strImgNo.c_str();

transfer.m_astrAllDirName.Add(csImgNo);

try

{

if (!transfer.UploadAll())

{

CString strlog(_T("[threadOperationTransfer]: "));

ServiceLog.write_log("[threadOperationTransfer]: ERROR! Upload error.");

CString csError = transfer.GetLastError();

ServiceLog.write_log((LPCWSTR)(strlog+ csError));

return -1; // FTP Error;

}

}

catch (...)

{

CString strlog(_T("[threadOperationTransfer]: "));

ServiceLog.write_log("[threadOperationTransfer]: ERROR! upload except:");

CString csError = transfer.GetLastError();

ServiceLog.write_log((LPCWSTR)(strlog+ csError));

return -1;

}

三.总结

通过以上的程序我们可以明白FTP的工作原理,因为基于应用,解释的还比较浅显。另外上传和下载需要比较久的时间,可以考虑设计多线程的方式来实现,这样不至于程序阻塞。

本文来自CSDN博客,转载请标明出处:

有几个java网络编程基础的选择题 哪位大神给下答案

、Applet为一种特殊的Panel,它可作为Java Applet程序的最外层容器。 ( )

2、Java的源码中定义多少个类,编译后结果就生成多少个以.class为后缀的字节码文 ( )

3、Java程序中,使用关键字new创建新的类对象,使用关键字free回收无用的类对象。 ( )

4、Java有垃圾回收机制,可在指定的时间使用内存回收程序释放内存对象。 ( )

5、构造函数用于创建类的实例对象,返回类型为void,构造函数名应与类名相同。 ( )

6、在异常处理中,假设try中的代码可能产生多种异常则可以对应多个catch语句,若catch中的参数类型有父子关系,此时应该将子类放在前面,父类放在后面。 ( )

7、含有abstract方法的类是抽象类,而抽象类中可以没有abstract方法。 ( )

8、Java的屏幕坐标以像素为单位,容器的左下角被确定为坐标的起点。 ( )

9、静态初始化器是在其所属的类加载内存时由系统自动调用执行。 ( )

10、在Java中可使用赋值号( )对对象赋值,相当于生成了一个各属性与赋值对象相同的新对象。 ( )

11、MVC是Model-View-Controller的简写。"View" 是应用的表示面(由JSP页面产生)。( )

12、MVC是Model-View-Controller的简写。"Controller" 是提供应用的处理过程控制(一般是一个Servlet),通过这种设计模型控制应用逻辑。( )

13、Tomcat是支持JSP引擎的一种服务器软件,可以通过server.xml文件修改服务器的配置信息。( )

14、通过Request.getParameterValues()可以获得某个参数的多个值( )

15、运行JSP需要有JSP引擎,Tomcat是支持JSP的Web服务器的一种。( )

16、Jsp使用的是Java脚本代码,可跨平台运行,运行开销小,具有速度快,可扩展性好及支持分布式处理等特点。 ( )

17、在定义了Bean的属性后,可不创建属性方法。( )

18、if语句是Java的条件分支语句,它控制程序以两条路径执行。( )

19、包是类的容器,用于保证类名空间的一致性。( )

20、JSP中不能使用HTML中的“!-- --”注释方式,只能使用JSP的“!-- --”的注释方式。

答案:仅供参考

T T F T T T T F T F T T T F F F T T T F

21.Java application中的主类必须包含方法main,以下哪项是main方法的正确参数?( )

A、 String args B、String ar[] C、Char arg D、StringBuffer args[]

22.以下对继承的正确描述是( )。

A、在Java中类只允许单一继承

B、在Java中一个类只能实现一个接口

C、在Java中一个类不能同时继承一个类和实现一个接口

D、在Java中接口只允许单一继承

23.paint()方法中的参数可使用哪种类型? ( )

A、Graphics B、Graphics2D C、String D、Color

24.以下不属于Java基本数据类型的是( )

A、int B、Boolean C、float D、char

25.以下哪项可能包含菜单条( )。

A、Panel B、Frame C、Applet D、Dialog

26.应使用哪种修饰符定义一个类域或类方法?( )

A、static B、package C、private D、public

27.在浏览器中执行applet 程序,以下选项中的哪个方法将被最先执行( )。

A、init() B、start() C、destroy() D、stop()

28.参考以下代码,关于该程序以下哪个说法是正确的?( )

public class Person{

static int arr[] = new int[3];

public static void main(String a[])

{

System.out.println(arr[0]); }

}

A、编译时将产生错误 B、编译时正确,运行时将产生错误

C、输出零 D、输出空

29.下列语句中,哪些关于Java内存回收的说明是正确的? ( )

A、程序员必须创建一个线程来释放内存

B、内存回收程序负责释放无用内存

C、内存回收程序允许程序员直接释放内存

D、内存回收程序可以在指定的时间释放内存对象

30.以下关键字中,可以用来对对象加互斥锁的是?( )

A、transient B、synchronized C、 serialize D、static

31.以下代码段执行后的输出结果为( )

int x=-3; int y=-10;

System.out.println(y%x);

A、 -1 B、2 C、1 D、3

32.有以下程序片段,下列哪个选项不能插入到行1。( )

1.

2.public class Interesting{

3.//do sth

4. }

A、import java.awt.*; B、package mypackage;

C、class OtherClass{ } D、public class MyClass{ }

33.假设有如下两个赋值语句:

a = Integer.parseInt(“5”);

b = Integer.valueOf(“5”).intValue();

下述说法正确的是( )。

A、a是整数类型变量,b是整数类对象。 B、a是整数类对象,b是整数类型变量。

C、a和b都是整数类对象并且值相等。 D、a和b都是整数类型变量并且值相等。

JAVA网络编程基础试题!300分!请一定要帮我做一下,两个解答题。一个编程题,重点是编程题,谢谢了!!

2.百度百科搜索很详细

3.附件中的代码仅供参考

TcpSocketServerDemo.java

package?yaoshun.InetAddress;

import?java.io.DataInputStream;

import?java.io.DataOutputStream;

import?java.io.IOException;

import?java.net.ServerSocket;

import?java.net.Socket;

import?java.util.ArrayList;

import?java.util.List;

import?java.util.Random;

/*

?*?客户端:TCP服务器端

?*/

public?class?TcpSocketServerDemo?{

private?ServerSocket?serverSocket;//?服务器连接

private?int?port;?//?服务器监听端口

private?ListSocket?sockets;

private?int?ranNumber;

/**

?*?服务器结束的标志

?*/

public?boolean?ISEND;

public?TcpSocketServerDemo(int?port)?{

this.port?=?port;

serverSocket?=?null;

sockets?=?new?ArrayListSocket();

ranNumber?=?new?Random().nextInt(50);

}

/*

?*?启动服务器

?*/

public?void?starServer()?{

try?{

//?第一步:建立服务器连接(绑定监听端口)

serverSocket?=?new?ServerSocket(port);

System.out.println("姚舜的服务器已经启动...");

Socket?socket;//?客户端连接(如果建立连接时,本机网络不容或服务器程序未启动则会抛出异常)

ServerThread?serverThread;

Thread?t2;

while?(!ISEND)?{

//?第二步:监听端口(获取客户端连接)

socket?=?serverSocket.accept();

if?(ISEND)?{

while?(!socket.isClosed())?{

socket.close();

Thread.sleep(100);

}

}?else?{

sockets.add(socket);

serverThread?=?new?ServerThread(this,?socket);

t2?=?new?Thread(serverThread);

t2.start();

}

}

for?(Socket?s?:?sockets)?{

s.close();

}

serverSocket.close();

}?catch?(Exception?e)?{

e.printStackTrace();

}

}

public?static?void?main(String[]?args)?{

TcpSocketServerDemo?tDemo?=?new?TcpSocketServerDemo(1000);

tDemo.starServer();

}

/**

?*?校验

?*?

?*?@param?i

?*?@return

?*/

public?int?check(int?i)?{

if?(i??ranNumber)?{

return?-1;

}?else?if?(i??ranNumber)?{

return?1;

}

return?0;

}

}

/**

?*?服务端处理线程

?*

?*/

class?ServerThread?implements?Runnable?{

private?TcpSocketServerDemo?tDemo;

private?Socket?socket;

private?DataInputStream?dis;//?输入流(读取数据)

private?DataOutputStream?dos;//?输出流(发送数据)

public?ServerThread(TcpSocketServerDemo?tDemo,?Socket?socket)?{

super();

this.tDemo?=?tDemo;

this.socket?=?socket;

try?{

dis?=?new?DataInputStream(socket.getInputStream());

dos?=?new?DataOutputStream(socket.getOutputStream());

}?catch?(IOException?e)?{

e.printStackTrace();

}

}

public?void?run()?{

String?message?=?"";

int?i;

int?index?=?0;

int?result?=?0;

while?(!message.equals("Quit")??index??5)?{

try?{

message?=?dis.readUTF();

}?catch?(IOException?e)?{

e.printStackTrace();

}

try?{

i?=?Integer.parseInt(message);

result?=?tDemo.check(i);

if?(result?==?1)?{

dos.writeUTF("数字大了");

}?else?if?(result?==?-1)?{

dos.writeUTF("数字小了");

}

if?(result?==?0)?{

dos.writeUTF("猜中了");

break;

}

}?catch?(NumberFormatException?|?IOException?e)?{

continue;

}

index++;

}

try?{

dis.close();

dos.close();

socket.close();

}?catch?(IOException?e)?{

e.printStackTrace();

}

}

}

TcpSocketClientDemo.java

package?yaoshun.InetAddress;

import?java.io.DataInputStream;

import?java.io.DataOutputStream;

import?java.io.IOException;

import?java.net.Socket;

import?java.net.UnknownHostException;

import?java.util.Scanner;

/*

?*?演示类:TCP客户端

?*/

public?class?TcpSocketClientDemo?{

private?Socket?socket;//?客户端连接(如果建立连接时,本机网络不容或服务器程序未启动则会抛出异常)

private?DataInputStream?dis;//?输入流(读取数据)

private?DataOutputStream?dos;//?输出流(发送数据)

//?private?String?serverIP;//?服务器IP地址

//?private?int?serverPort;//?服务器监听端口

private?String?sendData;//?发送的数据

public?TcpSocketClientDemo(String?serverIP,?int?serverPort)?throws?UnknownHostException,?IOException?{

//?this.serverIP?=?serverIP;

//?this.serverPort?=?serverPort;

socket?=?new?Socket(serverIP,?serverPort);

dis?=?new?DataInputStream(socket.getInputStream());

dos?=?new?DataOutputStream(socket.getOutputStream());

sendData?=?null;

startClient();

}

public?void?startClient()?{

try?{

//?第一步:创建客户端连接

System.out.println("===我的客户端界面===");

//?第二步:客户端向服务器发送数据

int?i?=?0;

Scanner?input?=?new?Scanner(System.in);

while?(i??5)?{

System.out.println("请输入你的内容(客户端的):");

sendData?=?input.nextLine();

if?(sendData.equals("quit"))?{

break;

}

dos.writeUTF(sendData);

sendData?=?dis.readUTF();

System.out.println("接收到服务器内容:"?+?sendData);

if?(i?==?5)?{

System.out.println("超过允许次数,请重新连接服务器.");

}

if?(sendData.equals("猜中了"))?{

i?=?5;

}

i++;

}

input.close();

}?catch?(Exception?e)?{

e.printStackTrace();

}?finally?{

//?第四步:关闭输入流、输出流和客户端连接

try?{

dis.close();

dos.close();

socket.close();

}?catch?(Exception?e)?{

e.printStackTrace();

}

}

}

public?static?void?main(String[]?args)?{

try?{

new?TcpSocketClientDemo("127.0.0.1",?1000);

}?catch?(IOException?e)?{

e.printStackTrace();

}

}

}

(责任编辑:IT教学网)

更多

推荐新手入门文章