I have the following code on my server :
public class ClientThread extends Thread
{
Socket clientSocket;
DataInputStream dis;
ObjectInputStream ois;
DataOutputStream dos;
public ClientThread(Socket acceptedSocket)
{
clientSocket = acceptedSocket;
try
{
dis = new DataInputStream(clientSocket.getInputStream());
ois = new ObjectInputStream(clientSocket.getInputStream());
dos = new DataOutputStream(clientSocket.getOutputStream());
}
catch (Exception e)
{
System.out.println("ClientThread " + e.getMessage());
}
}
The rest of the class is omitted
Why does my application freeze when I call the socket input stream twice without throwing an exception?
Yes, I could just save the input stream into the InputStream variable and use this variable to get the type of input stream I want, but I'm curious why it hangs when called twice from the socket?
Who cares? Does the called twice change nothing?
EDIT: Even when saving the input stream to the InputStream variable and using this variable to get the desired input stream (DataInputStream and ObjectInputStream), does it still freeze when called more than once?
Example:
public class ClientThread extends Thread
{
Socket clientSocket;
InputStream is;
DataInputStream dis;
ObjectInputStream ois;
DataOutputStream dos;
public ClientThread(Socket acceptedSocket)
{
clientSocket = acceptedSocket;
try
{
is = clientSocket.getInputStream();
dis = new DataInputStream(is);
ois = new ObjectInputStream(is);
dos = new DataOutputStream(clientSocket.getOutputStream());
}
catch (Exception e)
{
System.out.println("ClientThread " + e.getMessage());
}
}
The rest of the class is omitted
Client Code :
public class LoginLogic_Callable implements Callable<String>
{
Socket socket;
String actionString;
String username;
String password;
public LoginLogic_Callable(Socket sentSocket, String sentUsername, String sentPassword)
{
socket = sentSocket;
username = sentUsername;
password = sentPassword;
}
@Override
public String call() throws Exception
{
String userLoginStatus = null;
try
{
DataOutputStream loginUserData = new DataOutputStream(socket.getOutputStream());
ObjectOutputStream oos = new ObjectOutputStream(socket.getOutputStream());
DataInputStream dis = new DataInputStream(socket.getInputStream());
String[] loginUserInfo = new String[2];
loginUserInfo[0] = username;
loginUserInfo[1] = password;
loginUserData.writeUTF("userlogin");
oos.writeObject(loginUserInfo);
loginUserData.flush();
oos.flush();
userLoginStatus = dis.readUTF();
loginUserData.close();
oos.close();
dis.close();
}
catch (Exception e)
{
}
return userLoginStatus;
}
}