SOCKET服务器并发测试,如何自己编写测试程序 在JAVA中SOCKET服务器并发测试,如何自己编写测试程序??????????? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 import javax.swing.*;import java.util.Scanner;import java.awt.*;import java.awt.event.*;import java.io.*;import java.net.*;public class GoodTcp extends JFrame implements ActionListener {// 主类 static TextArea ta = new TextArea();// 定义一个文本框 static JButton j1 = new JButton("侦听"); static JButton j2 = new JButton("连接"); static JButton j3 = new JButton("发送"); static TextField tf1 = new TextField("127.0.0.1", 20); // IP static TextField tf2 = new TextField("8888", 5); // port static TextField tf3 = new TextField(40); // 发送 static Socket skt; class MyThread extends Thread { public void run() { try { BufferedReader br = new BufferedReader(new InputStreamReader( skt.getInputStream())); while (true) { ta.append("\n"+"[" + skt.getInetAddress() + "]说:"+ br.readLine()); } } catch (Exception e) { e.printStackTrace(); } } } public void work() { ta.append("\n"+"[" + skt.getInetAddress() + "]"+"连接成功!"); new MyThread().start(); } public void actionPerformed(ActionEvent e) { try { if (e.getSource() == j1) { // 按纽1的事件 ServerSocket server = new ServerSocket(Integer.parseInt(tf2 .getText())); skt = server.accept(); work(); } if (e.getSource() == j2) { // 按纽2的事件 skt = new Socket(tf1.getText(), Integer.parseInt(tf2.getText())); work(); } if (e.getSource() == j3) { // 按纽3的事件 ta.append("\n"+"我说:"+tf3.getText()); PrintWriter pw = new PrintWriter(skt.getOutputStream()); pw.println(tf3.getText()); //ta.setText(tf3.getText()); pw.flush(); } } catch (Exception ee) { ta.append("\n"+"操作失败"); } } public static void main(String[] args) throws Exception { GoodTcp gt = new GoodTcp(); gt.setBounds(100, 100, 450, 300); gt.setTitle("聊天软件"); Container c = gt.getContentPane(); JPanel jp1 = new JPanel(); JPanel jp2 = new JPanel(); JLabel jl1 = new JLabel("IP"); JLabel jl2 = new JLabel("port"); j1.addActionListener(gt); j2.addActionListener(gt); j3.addActionListener(gt); jp1.add(jl1); jp1.add(tf1); jp1.add(jl2); jp1.add(tf2); jp1.add(j1); jp1.add(j2); c.add(jp1, BorderLayout.NORTH); c.add(ta, BorderLayout.CENTER); jp2.setLayout(new BorderLayout()); jp2.add(tf3, BorderLayout.CENTER); jp2.add(j3, BorderLayout.EAST); c.add(jp2, BorderLayout.SOUTH); gt.setVisible(true); }}运行2次就行了,先运行一个,点侦听,那个连接,就可以通话了 大虾,SOCKET服务器并发测试???????? 我怎么知道SOCKET服务器的最大并发数????????????????????????如何写测试用例?????????????????????????????????????????????? 写个客户程序,不断的建立socket连接,看服务器可以承受多少socket连接。 新手遇到java的一个小问题,希望大家可以帮帮! 统计任意一字符串中的每个字符出现次数,内容中包含有中文且只能使用一次循环. 接口啊!救命啊!为什么我们要用接口?为什么他们非要给我们接口? 紧急的线程问题 按钮监听难题 请问如何去掉JTree中结点左边的连线? 关于JCreator PRO 3.5的问题? 求java操作excel的jxl.jar 怎么得到本机的IP地址? 做了个JAVA小游戏,当提前送给大家的圣诞礼物,进来看看啊:) 救命!!!!!!! eclips的大括号问题
import java.util.Scanner;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.net.*;public class GoodTcp extends JFrame implements ActionListener {// 主类
static TextArea ta = new TextArea();// 定义一个文本框
static JButton j1 = new JButton("侦听");
static JButton j2 = new JButton("连接");
static JButton j3 = new JButton("发送");
static TextField tf1 = new TextField("127.0.0.1", 20); // IP
static TextField tf2 = new TextField("8888", 5); // port
static TextField tf3 = new TextField(40); // 发送
static Socket skt; class MyThread extends Thread {
public void run() {
try {
BufferedReader br = new BufferedReader(new InputStreamReader(
skt.getInputStream())); while (true) {
ta.append("\n"+"[" + skt.getInetAddress() + "]说:"+ br.readLine());
}
} catch (Exception e) {
e.printStackTrace();
}
}
} public void work() {
ta.append("\n"+"[" + skt.getInetAddress() + "]"+"连接成功!");
new MyThread().start(); } public void actionPerformed(ActionEvent e) {
try {
if (e.getSource() == j1) { // 按纽1的事件
ServerSocket server = new ServerSocket(Integer.parseInt(tf2
.getText()));
skt = server.accept();
work();
}
if (e.getSource() == j2) { // 按纽2的事件
skt = new Socket(tf1.getText(), Integer.parseInt(tf2.getText()));
work();
}
if (e.getSource() == j3) { // 按纽3的事件
ta.append("\n"+"我说:"+tf3.getText());
PrintWriter pw = new PrintWriter(skt.getOutputStream());
pw.println(tf3.getText());
//ta.setText(tf3.getText());
pw.flush();
}
} catch (Exception ee) {
ta.append("\n"+"操作失败");
}
} public static void main(String[] args) throws Exception {
GoodTcp gt = new GoodTcp();
gt.setBounds(100, 100, 450, 300);
gt.setTitle("聊天软件");
Container c = gt.getContentPane(); JPanel jp1 = new JPanel(); JPanel jp2 = new JPanel(); JLabel jl1 = new JLabel("IP");
JLabel jl2 = new JLabel("port"); j1.addActionListener(gt);
j2.addActionListener(gt);
j3.addActionListener(gt); jp1.add(jl1);
jp1.add(tf1);
jp1.add(jl2);
jp1.add(tf2);
jp1.add(j1);
jp1.add(j2);
c.add(jp1, BorderLayout.NORTH); c.add(ta, BorderLayout.CENTER); jp2.setLayout(new BorderLayout());
jp2.add(tf3, BorderLayout.CENTER);
jp2.add(j3, BorderLayout.EAST);
c.add(jp2, BorderLayout.SOUTH); gt.setVisible(true); }
}运行2次就行了,先运行一个,点侦听,那个连接,就可以通话了
如何写测试用例??????????????????????????????????????????????