Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/331.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java小程序未加载-客户端/服务器_Java_Applet_Client - Fatal编程技术网

Java小程序未加载-客户端/服务器

Java小程序未加载-客户端/服务器,java,applet,client,Java,Applet,Client,我有这个服务器和一个小程序。服务器加载良好,因为它可以检测新用户何时加载客户端并连接。问题是小程序不会加载,就像它卡在加载屏幕上一样 以下是我的问题的视频说明,如果您愿意: 如果希望看到问题发生,建议观看视频 Server.java 我怎么修好的 通过在单独的线程中处理连接 import java.io.*; import java.net.*; import java.util.*; public class Server{ static Socket clientSocket

我有这个服务器和一个小程序。服务器加载良好,因为它可以检测新用户何时加载客户端并连接。问题是小程序不会加载,就像它卡在加载屏幕上一样

以下是我的问题的视频说明,如果您愿意: 如果希望看到问题发生,建议观看视频

Server.java

我怎么修好的

通过在单独的线程中处理连接

import java.io.*;
import java.net.*;
import java.util.*;

public class Server{

    static  Socket clientSocket = null;
    static  ServerSocket serverSocket = null;

    static  clientThread t[] = new clientThread[10];


    public static void main(String args[]) {

    // The default port    

    int port_number=2222;

    if (args.length < 1)
        {
        System.out.println("Starting game server...\nPort number: "+port_number);
        } else {
        port_number=Integer.valueOf(args[0]).intValue();
        }

        try {
        serverSocket = new ServerSocket(port_number);
        System.out.println("\n**********************\n*** SERVER STARTED ***\n**********************\n");
        }
        catch (IOException e)
        {System.out.println(e);}

    while(true){
        try {
        clientSocket = serverSocket.accept();
        System.out.println("*** SOMEONE CONNECTED ***\n");
        for(int i=0; i<=9; i++){
            if(t[i]==null)
            {
                (t[i] = new clientThread(clientSocket,t)).start();
                break;
            }
        }
        }
        catch (IOException e) {
        System.out.println(e);}
    }
    }
}

class clientThread extends Thread{

    BufferedReader is = null;
    PrintStream os = null;
    Socket clientSocket = null;
    clientThread t[];
    Random roll = new Random();

    public clientThread(Socket clientSocket, clientThread[] t){
    this.clientSocket=clientSocket;
        this.t=t;
    }

    public void run()
    {
        System.out.println("Check 1");
    String line;
        String name;
        int py;
    try{
        System.out.println("Check 2");
        is = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
        System.out.println("Check 3");
        os = new PrintStream(clientSocket.getOutputStream());
        System.out.println("Check 4");
        int px = roll.nextInt(200);
        //os.println("Enter your name.");
        System.out.println("Check 5");
        name = "Guest #" + roll.nextInt(6);
        System.out.println("Check 6\n");
        System.out.println(name+" has entered the game. Their attack: " + px);
        System.out.println("Check 7");
        for(int i=0; i<=9; i++)
        if (t[i]!=null && t[i]!=this)
            t[i].os.println("*** A new user "+name+" entered the chat room !!! ***" );
            System.out.println("Check 8");
        while (true) {
            System.out.println("Check 9");
        line = is.readLine();
                if(line.startsWith("/quit")) break;
        for(int i=0; i<=9; i++)
            if (t[i]!=null)  t[i].os.println("<"+name+":"+px+"> "+line); // someone said something
        }
        for(int i=0; i<=9; i++)
        if (t[i]!=null && t[i]!=this) {
        System.out.println("\n" + name + " has left!\n");
            t[i].os.println("*** The user "+name+" is leaving the chat room !!! ***" );
        }

        os.println("*** Bye "+name+" ***");

        for(int i=0; i<=9; i++) {
        if (t[i]==this) t[i]=null;
        System.out.println("\nSomeone has left!\n");
    }

        is.close();
        os.close();
        clientSocket.close();
    }
    catch(IOException e){};
    }
}
import java.io.*;
import java.applet.Applet;
import java.net.*;
import javax.swing.*;
import java.awt.*;
import java.util.*;

public class ClientApplet extends Applet {

    public static TextArea chat;

public void init() {
        chat = new TextArea(10,40);
            add(chat);
    chat.append("Hey!");


Socket s = null;

try {
s = new Socket(getParameter("host"), Integer.valueOf(getParameter("port")));
//s = new Socket("localhost", 4444);
InputStream in = s.getInputStream();
int buf = -1;
while ((buf = in.read()) != '.') {
System.out.print((char)buf);
}
}catch(Exception e) {
e.printStackTrace();
}
finally {
try {
    s.close();
    } catch(IOException e)
    { }
}

}
}