serveur.java

来自「TCP Connection using java」· Java 代码 · 共 41 行

JAVA
41
字号
import java.net.*;
import java.io.*;
public class serveur{
ServerSocket ss;
public serveur(int port) throws IOException
{
ss=new ServerSocket(port);
}
public void go()
{
while (true)
{
	try
	{
		Socket so = ss.accept();
		echange(so.getInputStream(), so.getOutputStream());
		so.close();
	}
	catch (IOException e)
	{ }
}
}
public void echange(InputStream is,OutputStream os) throws IOException
{
DataOutputStream dos=new DataOutputStream(os);
dos.writeUTF("Hello net Wrold!!");

DataInputStream dis = new DataInputStream(is);
String tmp = dis.readUTF();
System.out.println(tmp);
}
public static void main(String argc[])
{
	try{
		
serveur s = new serveur(3000);
s.go();
	}
	catch(IOException e){}
}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?