java socket传输中用到split差分用户名密码

为什么我的代码不能支持多次登录,每登陆一次就要将服务器端代码再运行一次

// 客户端 传送账号密码
PrintWriter pw = new PrintWriter(new OutputStreamWriter((s.getOutputStream())),true);
pw.println(user+"%"+pass);

    //客户端     返回服务端验证结果
    BufferedReader br = new BufferedReader( new InputStreamReader(s.getinputstream()));
    String yorn = br.readLine();
        if(yorn.equals("1")){
                this.setVisible(false);
                new QQMain();//密码账号正确 进如QQ主页面
            }else{
                JOptionPane.showMessageDialog(this, "对不起,用户名或密码错误");
            }

//服务端 接收用户名和密码
BufferedReader br = new BufferedReader( new InputStreamReader(s.getinputstream()));
    String uandp = br.readLine();
    String u ="";
    String p ="";
    try{
        u = uandp.split("%")[0];//取账号
        p = uandp.split("%")[1];//取密码
    }catch(Exception e){}

PrintWriter pw = new PrintWriter(new OutputStreamWriter((s.getOutputStream())),true);
    if(u.equals("liangyu")&&p.equals("521")){
        //如果账号密码正确发送正确信息到客户端
        pw.println("1");
    }else{
        //发送错误信息到客户端
        pw.println("0");
    }

附上错误
java.net.ConnectException: Connection refused: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
at java.net.Socket.connect(Socket.java:519)
at java.net.Socket.connect(Socket.java:469)
at java.net.Socket.(Socket.java:366)
at java.net.Socket.(Socket.java:180)
at 客户端界面.QQLogin.actionPerformed(QQLogin.java:81)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
at java.awt.Component.processMouseEvent(Component.java:6216)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3265)
at java.awt.Component.processEvent(Component.java:5981)
at java.awt.Container.processEvent(Container.java:2041)
at java.awt.Component.dispatchEventImpl(Component.java:4583)
at java.awt.Container.dispatchEventImpl(Container.java:2099)
at java.awt.Component.dispatchEvent(Component.java:4413)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4556)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4220)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4150)
at java.awt.Container.dispatchEventImpl(Container.java:2085)
at java.awt.Window.dispatchEventImpl(Window.java:2475)
at java.awt.Component.dispatchEvent(Component.java:4413)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
java.net.ConnectException: Connection refused: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
at java.net.Socket.connect(Socket.java:519)
at java.net.Socket.connect(Socket.java:469)
at java.net.Socket.(Socket.java:366)
at java.net.Socket.(Socket.java:180)
at 客户端界面.QQLogin.actionPerformed(QQLogin.java:81)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
at java.awt.Component.processMouseEvent(Component.java:6216)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3265)
at java.awt.Component.processEvent(Component.java:5981)
at java.awt.Container.processEvent(Container.java:2041)
at java.awt.Component.dispatchEventImpl(Component.java:4583)
at java.awt.Container.dispatchEventImpl(Container.java:2099)
at java.awt.Component.dispatchEvent(Component.java:4413)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4556)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4220)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4150)
at java.awt.Container.dispatchEventImpl(Container.java:2085)
at java.awt.Window.dispatchEventImpl(Window.java:2475)
at java.awt.Component.dispatchEvent(Component.java:4413)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)

3个回答

连接被拒绝,应该是服务端有问题,你服务端是怎么实现的,能大概说一下吗?还有当一个客户端连接之后要启动一个线程来负责与该客户端交互,写的方法要实现同步,防止窜了。。。

qq_30174839
我帅的无法无天 无论账号密码正确还是错误 都只能用一次,用一次没有错误,正常运行,但如果输入错误再次输入就出错了
3 年多之前 回复
qq_30174839
我帅的无法无天 用的MyEclipse才学没几天,两个程序间通讯,没用SQL呢还,就是用的Socket通讯 两次(第一次服务端收账号密码,客户端发送账号密码。第二次服务端发送账号验证,客户端接收
3 年多之前 回复
qq_30174839
我帅的无法无天 用的MyEclipse才学没几天,两个程序间通讯,没用SQL呢还,就是用的Socket通讯 两次(第一次服务端收账号密码,客户端发送账号密码。第二次服务端发送账号验证,客户端接收)
3 年多之前 回复

第一次用这个 ,谢谢大家了帮忙了 ,格式我的锅

第一次运行正常,界面是QQ登陆界面,输入错误账号密码,无异常,再次输入账号密码就出问题了,
只能运行一次,不能支持多次登录,每登陆一次就要将服务器端代码再运行一次

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问