KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I am sending Object for client to server modifying that object at server side and resending it to client. Sending object form client to server is fine its working properly but when I am sending object back it gives exception Socket is closed. Here is code. IntString and ParentObj are classes of which I'm sending objects. Client1 class: 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 = new Send_recv(s); snd.sendObj((ParentObj) obj); if (s.isClosed()) { System.out.println("Closed"); // s.connect(null); } obj1 = snd.recObj(); obj = (IntString) obj1; if (obj != null) { for (counter_1 = 0; counter_1 < obj.length_of_row; counter_1++) { System.out.println(obj.row[counter_1]); obj.row[counter_1]++; } } // s.close(); } catch (Exception e) { System.out.println(e); } } } Server Class import java.net.*; import java.io.*; public class Server1 { public static void main(String args[]) { IntString obj; ParentObj obj1; int port = 6789, counter_1; try { ServerSocket ss = new ServerSocket(port);
Tags (comma-separated)
Save Edits
Cancel