• 大小: 36KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-05-18
  • 语言: Java
  • 标签: java  socket  多线程  swt  

资源简介

该软件是一个基于java语言的socket编程,可以实现单个服务器对应多个客户端的聊天。采用swt,功能还是比较完善的。

资源截图

代码片段和文件信息

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.Socket;
import java.net.UnknownHostException;

import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;


public class Client {

protected Shell shlChartclient;
private Text port;
private Text hostip;
public  static Text text_msg;
private Text text_send;
private Socket socket;
private String msg;//客户端输入的信息
private String serverMsg;



/**
 * Launch the application.
 * @param args
 */
public static void main(String[] args) {
try {
Client window = new Client();
window.open();
} catch (Exception e) {
e.printStackTrace();
}
}

/**
 * Open the window.
 */
public void open() {
Display display = Display.getDefault();
createContents();
shlChartclient.open();
shlChartclient.layout();
while (!shlChartclient.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
}

/**
 * Create contents of the window.
 */
protected void createContents() {
shlChartclient = new Shell();
shlChartclient.setSize(441 361);
shlChartclient.setText(“Chart_Client“);

Composite composite = new Composite(shlChartclient SWT.NONE);
composite.setBounds(37 10 302 114);

Label lblNewLabel = new Label(composite SWT.NONE);
lblNewLabel.setBounds(22 10 61 17);
lblNewLabel.setText(“port:“);

Label lblNewLabel_1 = new Label(composite SWT.NONE);
lblNewLabel_1.setBounds(22 50 61 17);
lblNewLabel_1.setText(“host IP:“);

port = new Text(composite SWT.BORDER);
port.setText(“8000“);
port.setBounds(89 10 73 23);

hostip = new Text(composite SWT.BORDER);
hostip.setText(“127.0.0.1“);
hostip.setBounds(89 47 146 23);

Button connect = new Button(composite SWT.NONE);
connect.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
try {
socket=new Socket(hostip.getText()Integer.parseInt(port.getText()));
Client.text_msg.append(“client 已经启动...\n“);
ClientThread clientthread=new ClientThread();
clientthread.setSocket(socket);
clientthread.start();
} catch (NumberFormatException | IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}

}
});
connect.setBounds(89 77 80 27);
connect.setText(“connect“);

text_msg = new Text(shlChartclient SWT.MULTI);
text_msg.setBounds(37 145 302 122);

text_send = new Text(shlChartclient S

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       3073  2014-03-15 10:57  ChatClient\.classpath

     文件        386  2014-03-15 10:57  ChatClient\.project

     文件        598  2014-03-15 10:57  ChatClient\.settings\org.eclipse.jdt.core.prefs

     文件       1547  2014-06-23 21:34  ChatClient\bin\Client$1.class

     文件       1635  2014-06-23 21:34  ChatClient\bin\Client$2.class

     文件       3303  2014-06-23 21:34  ChatClient\bin\Client.class

     文件        976  2014-06-23 21:34  ChatClient\bin\ClientThread$1.class

     文件        694  2014-06-23 21:34  ChatClient\bin\ClientThread$2.class

     文件       2069  2014-06-23 21:34  ChatClient\bin\ClientThread.class

     文件       3817  2014-03-21 17:15  ChatClient\src\Client.java

     文件       1644  2014-03-27 21:59  ChatClient\src\ClientThread.java

     文件       3073  2014-03-15 00:03  ChatServer\.classpath

     文件        386  2014-03-15 00:03  ChatServer\.project

     文件        598  2014-03-15 00:03  ChatServer\.settings\org.eclipse.jdt.core.prefs

     文件      11089  2014-07-01 19:39  ChatServer\bin\org\eclipse\wb\swt\SWTResourceManager.class

     文件       2175  2014-07-01 19:39  ChatServer\bin\Server$1.class

     文件       1391  2014-07-01 19:39  ChatServer\bin\Server$2.class

     文件        821  2014-07-01 19:39  ChatServer\bin\Server$3$1.class

     文件       1991  2014-07-01 19:39  ChatServer\bin\Server$3.class

     文件       1064  2014-07-01 19:39  ChatServer\bin\Server$4.class

     文件       1148  2014-07-01 19:39  ChatServer\bin\Server$5.class

     文件       5779  2014-07-01 19:39  ChatServer\bin\Server.class

     文件        680  2014-07-01 19:39  ChatServer\bin\TalkThread$1.class

     文件        941  2014-07-01 19:39  ChatServer\bin\TalkThread$2.class

     文件       2065  2014-07-01 19:39  ChatServer\bin\TalkThread.class

     文件        736  2014-07-01 19:39  ChatServer\bin\TipDialog$1.class

     文件       2639  2014-07-01 19:39  ChatServer\bin\TipDialog.class

     文件      14540  2014-03-15 10:16  ChatServer\src\org\eclipse\wb\swt\SWTResourceManager.java

     文件       6668  2014-03-27 22:08  ChatServer\src\Server.java

     文件       1833  2014-03-27 21:49  ChatServer\src\TalkThread.java

............此处省略20个文件信息

评论

共有 条评论