1.socketjavaԴ?源码?
2.用Java Socket编程,实现简单的源码网站流量统计 源码Echo功能
socketjavaԴ??
//客户端
public static void main(String[] args) throws Exception
{
Socket socket = new Socket(".0.0.1", );
OutputStream os = socket.getOutputStream();
os.write("hello world".getBytes());
os.close();//客户端使用完流之后记得要关闭!!源码上门取源码新闻
}
//服务端
public static void main(String[] args) throws Exception
{
ServerSocket ss = new ServerSocket();
Socket socket = ss.accept();
InputStream is = socket.getInputStream();
byte[] buffer = new byte[];
int length = 0;
while (-1 != (length = is.read(buffer,源码最新暗宝源码 0, buffer.length)))//这句错了,是源码脚本怎么获取源码不等于!
{
String str = new String(buffer,源码内核rt源码分析 0, length);
System.out.println("welcome "+str);
}
}
用Java Socket编程,实现简单的源码Echo功能
// 服务器
import java.io.*;
import java.net.*;
public class MyServer {
public static void main(String[] args) throws IOException{
ServerSocket server=new ServerSocket();
while (true) {
Socket client=server.accept();
BufferedReader in=new BufferedReader(new InputStreamReader(client.getInputStream()));
PrintWriter out=new PrintWriter(client.getOutputStream());
while(true){
String str=in.readLine();
System.out.println(str);
out.println("has receive....");
out.flush();
if(str.equals("exit"))
break;
}
client.close();
}
}
}
// 客户端
import java.net.*;
import java.io.*;
public class Client{
static Socket server;
public static void main(String[] args)throws Exception{
server=new Socket(InetAddress.getLocalHost(),);
BufferedReader in=new BufferedReader(new InputStreamReader(server.getInputStream()));
PrintWriter out=new PrintWriter(server.getOutputStream());
BufferedReader wt=new BufferedReader(new InputStreamReader(System.in));
while(true){
String str=wt.readLine();
out.println(str);
out.flush();
if(str.equals("end")){
break;
}
System.out.println(in.readLine());
}
server.close();
}
}
2024-11-19 01:40
2024-11-19 01:21
2024-11-19 01:18
2024-11-19 01:13
2024-11-19 00:42
2024-11-19 00:33
2024-11-19 00:18
2024-11-19 00:10