////////////客服端
package com.me.server2;import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.InetAddress;
import java.net.Socket;import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;import com.me.server.MultiJabberServer;/**
 * @author oath 创建时间:2005-9-8
 * 
 * TODO 要更改此生成的类型注释的模板,请转至 窗口 - 首选项 - Java - 代码样式 - 代码模板
 */
public class ClientView { private Text text_1; private Text text; protected Shell shell; Socket socket; BufferedReader in; PrintWriter out; public static void main(String[] args) {
try {
ClientView window = new ClientView();
window.open();
} catch (Exception e) {
e.printStackTrace();
}
} public void Client() throws IOException {
InetAddress addr = InetAddress.getByName(null); try {
socket = new Socket(addr, 8808); in = new BufferedReader(new InputStreamReader(socket
.getInputStream()));
// Enable auto-flush:
out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(
socket.getOutputStream())), true); } catch (IOException e) {
}
finally {
      try {
        socket.close();
      } catch(IOException e) {}
}
} public void open() {
final Display display = Display.getDefault();
createContents();
shell.open();
shell.layout();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
} protected void createContents() {
shell = new Shell();
shell.setSize(500, 375);
shell.setText("SWT Application"); final Group group = new Group(shell, SWT.NONE);
group.setText("聊天记录");
group.setBounds(13, 35, 450, 230); text = new Text(group, SWT.BORDER);
text.setBounds(20, 20, 405, 195); text_1 = new Text(shell, SWT.BORDER);
text_1.setBounds(17, 300, 389, 25); final Button button = new Button(shell, SWT.NONE);
button.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
try {
Client();
} catch (Exception ex) { }
}
});
button.setText("连接服务器");
button.setBounds(360, 8, 85, 26); final Button button_1 = new Button(shell, SWT.NONE);
button_1.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
String word = text_1.getText();
System.out.println("       "+word);
out.println(word);
}
});
button_1.setText("发送");
button_1.setBounds(425, 300, 50, 25); final Label label = new Label(shell, SWT.NONE);
label.setText("发言:");
label.setBounds(25, 277, 65, 18);
}
}
///////////////////服务器的VIEW
package com.me.server2;import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;import com.me.server.ServeOneJabber;/**
 * @author oath 创建时间:2005-9-7
 * 
 * TODO 要更改此生成的类型注释的模板,请转至 窗口 - 首选项 - Java - 代码样式 - 代码模板
 */
public class ServerView { public Text text_2;
private Text text; protected Shell shell; public static void main(String[] args) { try {
ServerView window = new ServerView();
window.open();
} catch (Exception e) {
e.printStackTrace();
}
} public void Server() throws IOException {
int PORT = 8808;
ServerSocket s = new ServerSocket(PORT);
text_2.append("开始服务... ...");
try { while (true) { Socket socket = s.accept();
try {
System.out.println("有人接上");
new ServeChat(socket);
} catch (IOException e) { socket.close();
}
}
} finally {
s.close();
}
} public void open() {
final Display display = Display.getDefault();
createContents();
shell.open();
shell.layout();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
} protected void createContents() {
shell = new Shell();
shell.setSize(500, 375);
shell.setText("服务器"); final Group group = new Group(shell, SWT.NONE);
group.setText("信息");
group.setBounds(20, 10, 450, 270); final Label label = new Label(group, SWT.NONE);
label.setText("端口");
label.setBounds(348, 18, 34, 14); text = new Text(group, SWT.BORDER);
text.setBounds(386, 14, 40, 20); text_2 = new Text(group, SWT.BORDER);
text_2.setBounds(5, 41, 435, 219); final Button button = new Button(shell, SWT.NONE);
button.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
try {
Server();
} catch (Exception ex) { }
}
});
button.setText("开始服务");
button.setBounds(370, 300, 70, 20);
}
}//////////////////////服务器的SOCKET连接部分
package com.me.server2;import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.Socket;/**
 * @author oath
 * 创建时间:2005-9-7
 *
 * TODO 要更改此生成的类型注释的模板,请转至
 * 窗口 - 首选项 - Java - 代码样式 - 代码模板
 */
public class ServeChat extends Thread{
private Socket socket; private BufferedReader in; private PrintWriter out;


public ServeChat(Socket s) throws IOException {
socket = s;
in = new BufferedReader(new InputStreamReader(socket.getInputStream())); out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(socket
.getOutputStream())), true); start(); // Calls run()
}

public void run() {
System.out.println("run!");
try {
while (true) {
System.out.println("接受语句开始循环!");
String str = in.readLine();
if (str.equals("END"))
break;
System.out.println("Echoing: " + str);
/*ServerView sv = new ServerView();
sv.text_2.append("说:"+str);*/
}
System.out.println("closing...");
} catch (Exception e) {
} finally {
try {
socket.close();
} catch (IOException e) {
}
}
}
}
可以连接,但是一点客户端的发送对话,服务器就死机!!!!!!!!!!!!!!!!!