我将客户端的Object发送给服务器,在服务器端修改该对象并将其重新发送到客户端.从客户端发送对象到服务器很好,它正常工作,但当我发送对象时,它给出异常Socket关闭.这是代码.IntString和ParentObj是我正在发送对象的类.
Client1类:
import java.net.*;
import java.io.*;
public class Client1 {
public static void main(String args[]) {
int arr[] = new int[10];
int length = 6, i, counter_1;
ParentObj obj1;
for (i = 0; i < length; i++) {
arr[i] = i + 10;
}
try {
Socket s = new Socket("localhost", 6789);
IntString obj = new IntString(arr, length);
/*
* OutputStream os = s.getOutputStream();
* ObjectOutputStream oos = new ObjectOutputStream(os);
*
* oos.writeObject(obj);
* oos.close();
* os.close();
*/
Send_recv snd …Run Code Online (Sandbox Code Playgroud)