我想显示客户端接收到的图像并在服务器上显示该图像..但我保留了图像部分稍后完成,最初只是接收输入流并打印它。
问题是它正在接受客户端请求但不打印解码的字符串,即decodedString = Base64.decodeBase64(base64Code);
这是服务器的代码
import java.net.*;
import java.io.*;
import org.apache.commons.codec.binary.Base64;
import java.awt.*;
import javax.swing.*;
public class server {
private static DataInputStream dataInputStream;
private static DataOutputStream dataOutputStream;
public static void main(String[] args) throws IOException {
// create socket
ServerSocket servsock = new ServerSocket(14789);
Socket sock = servsock.accept();
dataInputStream = new DataInputStream(sock.getInputStream());
dataOutputStream = new DataOutputStream(sock.getOutputStream());
System.out.println("Accepted connection : " + sock);
String base64Code = dataInputStream.readUTF();
byte[] decodedString = null;
decodedString = Base64.decodeBase64(base64Code);
System.out.println("Image Successfully Manipulated!" + decodedString);
if (dataOutputStream != null) {
try {
dataOutputStream.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if (dataInputStream != null) {
try {
dataInputStream.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
sock.close();
}
public static String encodeImage(byte[] imageByteArray) {
return Base64.encodeBase64String(imageByteArray);
}
}
任何帮助将不胜感激。