gpt4 book ai didi

java - ObjectInputStream readInt() 不起作用

转载 作者:行者123 更新时间:2023-12-01 10:11:34 26 4
gpt4 key购买 nike

我无法执行 readInt() 但 readObject 工作正常。给我建议一些解决方案。我在服务器端使用以下代码:

ObjectInputStream din = new ObjectInputStream(s.getInputStream());
ObjectOutputStream dout = new ObjectOutputStream(s.getOutputStream());
s1 = (String) din.readObject();
switch (s1) {
case "signin":
int a = din.readInt();
dout.writeInt(3);
System.out.println(a);
Mobile = (String) din.readObject();
String Pass = (String) din.readObject();
dout.writeInt(1);
break;
}

我的客户端代码是:-

 public int getAuthenticate(final String Mobile, final String Pass,final String signin)
{
m_objThreadClient=new Thread(new Runnable() {
public void run()
{

try
{
clientSocket= new Socket(ipAddress,11);
oos = new ObjectOutputStream(clientSocket.getOutputStream());
ObjectInputStream ois =new ObjectInputStream(clientSocket.getInputStream());
oos.writeObject(signin);
oos.writeInt(2);
status = ois.readInt();
System.out.println(status);
oos.writeObject(Mobile);
oos.writeObject(Pass);
status = ois.read();
System.out.println("Server status="+status);
}
catch (Exception e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}

}
});

m_objThreadClient.start();

try{m_objThreadClient.join();}
catch (Exception e){e.printStackTrace();}
return status;
}

在执行这些操作时,我既没有打印“status”的值,也没有打印“a”的值。它只是挂着。如果我删除 readInt() 或 read() 它工作正常。

最佳答案

尝试

oos.writeObject(signin);
oos.flush();
oos.writeInt(2);
oos.flush();

希望它能成功。

关于java - ObjectInputStream readInt() 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36098661/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com