topic description
Why is there an error in the connection between the server and the client?
I want to access the server through multithreading, using socket, but.
Server
import java.io.*;
import java.net.*;
class server implements Runnable
{
ServerSocket s_socket;
Socket c_socket;
DataInputStream in=null;
DataOutputStream out=null;
InputStream in_data;
OutputStream out_data;
int i=0;
server(){
try {
s_socket=new ServerSocket(7063);
while(true) {
c_socket=s_socket.accept();
Thread t=new Thread(this);
t.start();
iPP;
}
}
catch(IOException e) {
System.out.println("");
}
}
public void run() {
try {
while(true) {
in_data=c_socket.getInputStream();
out_data=c_socket.getOutputStream();
in=new DataInputStream(in_data);
out=new DataOutputStream(out_data);
out.writeUTF("hello,");
String s=in.readUTF();
if(s.equals("end"))
{
in.close();
out.close();
c_socket.close();
}
System.out.println(""+i+":"+s+"\n");
Thread.sleep(200);
}
}
catch(IOException e) {System.out.println("");}
catch(Exception e_) {System.out.println("");}
}
}
:
import java.io.*;
import java.net.*;
public class 9_10 {
public static void main(String[] args) throws UnknownHostException, IOException {
int i=0;
DataInputStream in=null;
DataOutputStream out=null;
Socket c_socket;
c_socket=new Socket("100.68.233.237",7063);
try {
InputStream in_data=c_socket.getInputStream();
OutputStream out_data=c_socket.getOutputStream();
in=new DataInputStream(in_data);
out=new DataOutputStream(out_data);
}
catch(IOException e) {System.out.println("");}
try {
String s=""+in.readUTF();
System.out.println(s);
if(i>10) {
out.writeUTF("end");
in.close();
out.close();
c_socket.close();
}
else {
out.writeUTF("I am client");
iPP;
}
}
catch(IOException e) {
System.out.println("");
}
}
}