我想从我的客户机发送一个字符串列表到服务器。
服务器
ObjectOutputStream objectOutput = new ObjectOutputStream(connsock.getOutputStream());
public List<String> current_clients_listening_songs = new ArrayList<String>();
current_clients_listening_songs.add("client 1 is listening to" + song);//song variable is string
//send list to client
objectOutput.writeObject(current_clients_listening_songs);
客户
ObjectInputStream objectInput = new ObjectInputStream(clientSocket.getInputStream());
//get list from server
Object get_client_listening = objectInput.readObject();
ArrayList<String> client_listening_songs = new ArrayList<String>();
//make a new list with server's list data
client_listening_songs = (ArrayList<String>) get_client_listening;
//print data
for (int i = 0; i < client_listening_songs.size(); i++) {
System.out.println(client_listening_songs.get(i));
}
服务器确实在列表中添加了项,但是客户端没有得到它们,怎么了?
暂无答案!
目前还没有任何答案,快来回答吧!