import java.net.ServerSocket;
import java.net.Socket;
public class Server
{
public static void main(String[] args) throws Exception
{
ServerSocket serverSocket = new ServerSocket(5678);
while (true)
{
Socket socket = serverSocket.accept();
new ServerThread(socket).start();
}
}
}
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
public class Client
{
public static void main(String[] args) throws Exception
{
for (int i = 0; i < 5000; ++i)
{
Socket socket = new Socket("localhost", 5678);
InputStream is = socket.getInputStream();
OutputStream os = socket.getOutputStream();
String str = "This comes from client";
os.write(str.getBytes());
byte[] buffer = new byte[100];
int length = is.read(buffer);
String s = new String(buffer, 0, length);
System.out.println("string's length: " + s);
is.close();
os.close();
socket.close();
}
}
}
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
public class ServerThread extends Thread
{
private Socket socket;
public ServerThread(Socket socket)
{
this.socket = socket;
}
@Override
public void run()
{
try
{
InputStream is = socket.getInputStream();
OutputStream os = socket.getOutputStream();
byte[] buffer = new byte[100];
int length = is.read(buffer);
String content = new String(buffer, 0, length);
System.out.println("read from client: " + content);
int strLength = content.length();
String str = String.valueOf(strLength);
byte[] b = str.getBytes();
os.write(b);
is.close();
os.close();
socket.close();
}
catch (Exception ex)
{
ex.printStackTrace();
}
}
}
分享到:
相关推荐
3)网络包(java.net):支持Internet的TCP/IP协议,用于实现Socket编程;提供了与Internet的接口,支持URL连接,WWW的即时访问,并且简化了用户/服务器模型的程序设计。 4)抽象图形用户接口包(javax.swing):实现了...
Programming concepts are introduced through simple program examples accompanied by line-by-line code commentary that describes the purpose of every part of the program. The book's Web site contains ...
What Can a Network Program Do? Section 1.2. Security Section 1.3. But Wait! There's More! Chapter 2. Basic Network Concepts Section 2.1. Networks Section 2.2. The Layers of a Network ...
java 实现word,txt,excel,ppt转换pdf 1.在服务控制台,启动 openoffice 服务 安装OpenOffice成功后,您可以进入安装目录>/program/目录并运行以下命令启动OpenOffice服务: soffice -headless -accept="socket,...
Such as the commonly used QQ tools, web, MSN communication system tools.The system includes the development of a network chat server program and a network chat client program in two aspects....
支持两种启动模式:1.java -jar TCPServer.jar 7788 ,这种模式接收一个命令一个操作方式2.java -jar TCPServer.jar 7788 monitor ,这种模式用于对一个对象持续监控,并每秒通知一次客户端,客户端连接之后,除非...
程序计数器(Program Counter Register) 49 java虚拟机栈 50 java堆(Java Heap) 51 方法区 51 【JVM】JVM内存结构,GC垃圾收集解析 52 【JVM】双亲委派模型中,从顶层到底层,都是哪些类加载器,分别加载哪些类?...
� Google 提供了一套 Java 核心包 (J2SE 5,J2SE 6) 的有限子集,尚不承诺遵守 Java 任何 Java 规范 , 可能会造 成J ava 阵营的进一步分裂。 � 现有应用完善度不太够,需要的开发工作量较大。--------------------...
Program Execution — Program Execution Functions PS — PostScript document creation Pspell — Pspell Functions qtdom — qtdom Functions radius — Radius Rar — Rar Functions Readline — GNU Readline ...
Program Execution — Program Execution Functions PS — PostScript document creation Pspell — Pspell Functions qtdom — qtdom Functions radius — Radius Rar — Rar Functions Readline — GNU Readline ...
Program Execution Functions LXXXVII. Printer Functions LXXXVIII. Pspell Functions LXXXIX. GNU Readline XC. GNU Recode Functions XCI. 正则表达式函数库(Perl 兼容) XCII. qtdom Functions XCIII. 正则...
Program Execution Functions CXVIII. Pspell Functions CXIX. qtdom Functions CXX. Radius CXXI. Rar Functions CXXII. Perl 兼容正则表达式函数 CXXIII. POSIX 扩展正则表达式函数 CXXIV. runkit Functions CXXV...
Program Execution Functions CXVIII. Pspell Functions CXIX. qtdom Functions CXX. Radius CXXI. Rar Functions CXXII. Perl 兼容正则表达式函数 CXXIII. POSIX 扩展正则表达式函数 CXXIV. runkit Functions CXXV...
Program Execution Functions CXVIII. Pspell Functions CXIX. qtdom Functions CXX. Radius CXXI. Rar Functions CXXII. Perl 兼容正则表达式函数 CXXIII. POSIX 扩展正则表达式函数 CXXIV. runkit Functions CXXV...
Program Execution Functions CXVIII. Pspell Functions CXIX. qtdom Functions CXX. Radius CXXI. Rar Functions CXXII. Perl 兼容正则表达式函数 CXXIII. POSIX 扩展正则表达式函数 CXXIV. runkit ...
Program Execution Functions CXVIII. Pspell Functions CXIX. qtdom Functions CXX. Radius CXXI. Rar Functions CXXII. Perl 兼容正则表达式函数 CXXIII. POSIX 扩展正则表达式函数 CXXIV. runkit Functions CXXV...
Program Execution Functions CXVIII. Pspell Functions CXIX. qtdom Functions CXX. Radius CXXI. Rar Functions CXXII. Perl 兼容正则表达式函数 CXXIII. POSIX 扩展正则表达式函数 CXXIV. runkit Functions CXXV...
Program Execution Functions CXVIII. PostScript document creation CXIX. Pspell Functions CXX. qtdom Functions CXXI. Radius CXXII. Rar Functions CXXIII. GNU Readline CXXIV. GNU Recode Functions CXXV. ...
Program Execution Functions CXXXI. PostScript document creation CXXXII. Pspell Functions CXXXIII. qtdom Functions CXXXIV. Radius CXXXV. Rar Functions CXXXVI. GNU Readline CXXXVII. GNU Recode ...
socket socketserver ssl statistics struct subprocess sys telnetlib time timeit tkinter traceback tracemalloc typing unicodedata unittest.mock urllib.request urllib.robotparser venv ...