import java.io.*;
import java.net.InetAddress;
import java.net.Socket;
import java.util.Scanner;
//客户端代码
public class Client_home {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
try {
System.out.println("我自己的IP:"+InetAddress.getLocalHost());
InetAddress localHost = InetAddress.getLocalHost();
Socket socket = new Socket(InetAddress.getLocalHost(),19999);
//该线程用于发出图片文件
new Thread(){
@Override
public void run() {
OutputStream os=null;
FileInputStream fis=null;
try {
os = socket.getOutputStream();
fis = new FileInputStream("C:\\Users\\17767\\Desktop\\屏幕截图 170946.png");
BufferedInputStream bis = new BufferedInputStream(fis);
Java TCP协议下为什么服务器不能在接收完文件后给客户端答复?以及解决方法
最新推荐文章于 2022-07-03 12:50:25 发布
本文探讨了在Java TCP协议下,服务器无法在接收完文件后给客户端反馈的问题。通过分析代码,作者发现服务器在接收文件后会陷入阻塞状态,无法发送确认消息。解决方案是在客户端调用`shutdownOutput()`方法,以结束输出流,从而使服务器能够继续执行并发送确认信息。实验验证了此方法的有效性。
摘要由CSDN通过智能技术生成