Men jeg ved det ikke.
er ved at lave en server og en klient del at et lille chat prigram. Jeg udviker i jBuiler.
Jeg kan starte min server og min klient del op. Jeg kan også på min server del se når min klient starter op, og se klientens IP.
Det er når jeg vil chatte mellem server og klient og omvendt at jeg får fejl.
Jeg beklader hvis det roder lidt, men er ny i faget.
Min fejl er :
==========================================
java.lang.NullPointerException
at servergui.ServerGUIFrame.jButton4_mouseClicked(ServerGUIFrame.java:279)
at servergui.ServerGUIFrame_jButton4_mouseAdapter.mouseClicked(ServerGUIFrame.java:545)
at java.awt.AWTEventMulticaster.mouseClicked(AWTEventMulticaster.java:212)
at java.awt.Component.processMouseEvent(Component.java:5103)
at java.awt.Component.processEvent(Component.java:4897)
at java.awt.Container.processEvent(Container.java:1569)
at java.awt.Component.dispatchEventImpl(Component.java:3615)
at java.awt.Container.dispatchEventImpl(Container.java:1627)
at java.awt.Component.dispatchEvent(Component.java:3477)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:3483)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3207)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3128)
at java.awt.Container.dispatchEventImpl(Container.java:1613)
at java.awt.Window.dispatchEventImpl(Window.java:1606)
at java.awt.Component.dispatchEvent(Component.java:3477)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:456)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:145)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)
==========================================
Min Server Frame Kode Er:
==========================================
package servergui;
import java.awt.*;
import javax.swing.*;
import javax.swing.border.Border;
import javax.swing.border.TitledBorder;
import java.net.ServerSocket;
import java.net.*;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.PrintWriter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.*;
import java.io.InputStream;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.ParserConfigurationException;
import java.io.*;
import org.xml.sax.SAXException;
import javax.*;
import org.w3c.dom.Document;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.TransformerException;
import com.mysql.jdbc.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.ResultSet;
import java.util.Date;
import java.text.SimpleDateFormat;
import java.text.DateFormat;
import java.net.InetAddress;
public class ServerGUIFrame
extends JFrame {
ServerSocket minserver = null;
/**Lokal Maskine IP*/
String localMachineIP = "";
/**Maskine navnet*/
String serverName = "";
/**Dato & Tids Formatering*/
Date time = new Date();
DateFormat df1 = new SimpleDateFormat("yyyy-MM-dd");
DateFormat df2 = new SimpleDateFormat("HH:mm:ss");
DateFormat df3 = new SimpleDateFormat("yyyy-MM-dd");
DateFormat df4 = new SimpleDateFormat("HH:mm:ss");
/**Tråd Forbindelse*/
TraadForbindelse TraadForbindelse1 = null;
/**Portnummer Indtastninger*/
String portnummerIndtast;
/**MySql Forbindelse*/
Connection forb = null;
JPanel contentPane;
JPanel jPanel1 = new JPanel();
Border border1 = BorderFactory.createLineBorder(Color.black, 2);
Border border2 = new TitledBorder(border1, "Server Administration");
JTextField jTextField1 = new JTextField();
JLabel jLabel1 = new JLabel();
JButton jButton1 = new JButton();
JButton jButton2 = new JButton();
JButton jButton3 = new JButton();
JPanel jPanel2 = new JPanel();
Border border3 = BorderFactory.createLineBorder(Color.black, 2);
Border border4 = new TitledBorder(border3, "System Beskeder");
JPanel jPanel3 = new JPanel();
Border border5 = BorderFactory.createLineBorder(Color.black, 2);
Border border6 = new TitledBorder(border5, "Fejl Beskeder");
JScrollPane jScrollPane1 = new JScrollPane();
JScrollPane jScrollPane2 = new JScrollPane();
JTextArea jTextArea1 = new JTextArea();
JTextArea jTextArea2 = new JTextArea();
JPanel jPanel4 = new JPanel();
Border border7 = BorderFactory.createLineBorder(Color.black, 2);
Border border8 = new TitledBorder(border7, "In & Out Bound Beskeder");
JTextField jTextField2 = new JTextField();
JLabel jLabel2 = new JLabel();
JScrollPane jScrollPane3 = new JScrollPane();
JLabel jLabel3 = new JLabel();
JButton jButton4 = new JButton();
JPanel jPanel5 = new JPanel();
Border border9 = BorderFactory.createLineBorder(Color.black, 2);
Border border10 = new TitledBorder(border9, "MySql Logging");
JTextArea jTextArea3 = new JTextArea();
JScrollPane jScrollPane4 = new JScrollPane();
JTextArea jTextArea4 = new JTextArea();
JButton jButton5 = new JButton();
JButton jButton6 = new JButton();
JButton jButton7 = new JButton();
public ServerGUIFrame() {
try {
setDefaultCloseOperation(EXIT_ON_CLOSE);
jbInit();
}
catch (Exception exception) {
exception.printStackTrace();
}
}
/**
* Component initialization.
*
* @throws java.lang.Exception
*/
private void jbInit() throws Exception {
contentPane = (JPanel) getContentPane();
contentPane.setLayout(null);
setSize(new Dimension(450, 730));
setTitle("Server Delen Af Chat Programmet");
jPanel1.setBorder(border2);
jPanel1.setBounds(new Rectangle(11, 10, 427, 92));
jPanel1.setLayout(null);
jTextField1.setText("6666");
jTextField1.setBounds(new Rectangle(19, 44, 77, 20));
jLabel1.setFont(new java.awt.Font("Dialog", Font.BOLD, 11));
jLabel1.setText("Portnummer");
jLabel1.setBounds(new Rectangle(20, 23, 114, 22));
jButton1.setBounds(new Rectangle(99, 35, 94, 30));
jButton1.setText("Start Server");
jButton1.addMouseListener(new ServerGUIFrame_jButton1_mouseAdapter(this));
jButton2.setBounds(new Rectangle(203, 35, 93, 31));
jButton2.setText("Lurk Port");
jButton2.addMouseListener(new ServerGUIFrame_jButton2_mouseAdapter(this));
jButton3.setBounds(new Rectangle(304, 36, 92, 29));
jButton3.setText("Luk Server");
jButton3.addMouseListener(new ServerGUIFrame_jButton3_mouseAdapter(this));
jPanel2.setBorder(border4);
jPanel2.setBounds(new Rectangle(14, 114, 200, 123));
jPanel2.setLayout(null);
jPanel3.setBorder(border6);
jPanel3.setBounds(new Rectangle(228, 113, 207, 124));
jPanel3.setLayout(null);
jScrollPane1.setHorizontalScrollBarPolicy(JScrollPane.
HORIZONTAL_SCROLLBAR_ALWAYS);
jScrollPane1.setVerticalScrollBarPolicy(JScrollPane.
VERTICAL_SCROLLBAR_ALWAYS);
jScrollPane1.setBounds(new Rectangle(13, 22, 171, 90));
jScrollPane2.setHorizontalScrollBarPolicy(JScrollPane.
HORIZONTAL_SCROLLBAR_ALWAYS);
jScrollPane2.setVerticalScrollBarPolicy(JScrollPane.
VERTICAL_SCROLLBAR_ALWAYS);
jScrollPane2.setBounds(new Rectangle(12, 22, 183, 91));
jTextArea1.setText("");
jTextArea2.setText("jTextArea2");
jPanel4.setBorder(border8);
jPanel4.setBounds(new Rectangle(18, 252, 417, 238));
jPanel4.setLayout(null);
jTextField2.setText("jTextField2");
jTextField2.setBounds(new Rectangle(12, 36, 393, 19));
jLabel2.setText("Out Bound Beskeder");
jLabel2.setBounds(new Rectangle(160, 13, 117, 20));
jScrollPane3.setHorizontalScrollBarPolicy(JScrollPane.
HORIZONTAL_SCROLLBAR_ALWAYS);
jScrollPane3.setVerticalScrollBarPolicy(JScrollPane.
VERTICAL_SCROLLBAR_ALWAYS);
jScrollPane3.setBounds(new Rectangle(12, 79, 391, 112));
jLabel3.setText("In Bound Beskeder");
jLabel3.setBounds(new Rectangle(155, 60, 112, 21));
jButton4.setBounds(new Rectangle(155, 196, 106, 30));
jButton4.setText("Send besked");
jButton4.addMouseListener(new ServerGUIFrame_jButton4_mouseAdapter(this));
jPanel5.setBorder(border10);
jPanel5.setBounds(new Rectangle(21, 493, 411, 209));
jPanel5.setLayout(null);
jTextArea3.setText("jTextArea3");
jScrollPane4.setHorizontalScrollBarPolicy(JScrollPane.
HORIZONTAL_SCROLLBAR_ALWAYS);
jScrollPane4.setVerticalScrollBarPolicy(JScrollPane.
VERTICAL_SCROLLBAR_ALWAYS);
jScrollPane4.setBounds(new Rectangle(13, 22, 386, 139));
jTextArea4.setText("jTextArea4");
jButton5.setBounds(new Rectangle(10, 172, 112, 24));
jButton5.setText("Vis Connectede");
jButton5.addMouseListener(new ServerGUIFrame_jButton5_mouseAdapter(this));
jButton6.setBounds(new Rectangle(145, 172, 111, 24));
jButton6.setText("Server Trafik");
jButton6.addMouseListener(new ServerGUIFrame_jButton6_mouseAdapter(this));
jButton7.setBounds(new Rectangle(278, 171, 108, 25));
jButton7.setText("Clare Log");
jButton7.addMouseListener(new ServerGUIFrame_jButton7_mouseAdapter(this));
jButton3.addActionListener(new ServerGUIFrame_jButton3_actionAdapter(this));
contentPane.add(jPanel1);
contentPane.add(jPanel2);
jPanel2.add(jScrollPane1);
jScrollPane1.getViewport().add(jTextArea1);
contentPane.add(jPanel3);
contentPane.add(jPanel4);
contentPane.add(jPanel5);
jPanel5.add(jScrollPane4);
jPanel5.add(jButton5);
jPanel5.add(jButton7);
jPanel5.add(jButton6);
jScrollPane4.getViewport().add(jTextArea4);
jPanel4.add(jTextField2);
jPanel4.add(jLabel2);
jPanel4.add(jLabel3);
jPanel4.add(jScrollPane3);
jPanel4.add(jButton4);
jScrollPane3.getViewport().add(jTextArea3);
jPanel3.add(jScrollPane2);
jScrollPane2.getViewport().add(jTextArea2);
jPanel1.add(jLabel1);
jPanel1.add(jTextField1);
jPanel1.add(jButton2);
jPanel1.add(jButton1);
jPanel1.add(jButton3);
}
public void startserver()
{
jTextArea1.append("Server Startet:" + "\\n" + "Dato" + ":" + " " + df1.format(time) + "\\n" + "Kl." + ":" + " " + df2.format(time));
portnummerIndtast = jTextField1.getText();
TraadForbindelse1 = new TraadForbindelse(jTextArea1, jTextArea2, jTextArea3, jTextField2, jTextField1, jTextArea4);
Thread MinTraad;
MinTraad = new Thread(TraadForbindelse1);
MinTraad.start();
/**Ip Adresen Fra den Locale Maskine Start*/
try
{
java.net.InetAddress localMachine = java.net.InetAddress.getLocalHost();
localMachineIP = localMachine.getHostAddress();
jTextArea1.append("\\nServer IP: " + localMachineIP);
}
catch(java.net.UnknownHostException uhe)
{
jTextArea2.append("Fejl 2 - Error Getting Local IP - ServerGUIFrame\\n");
}
/**Ip Adresen Fra den Locale Maskine Slut*/
/**HostNavn Adresen Fra den Locale Maskine Start*/
try {
serverName = java.net.InetAddress.getLocalHost().getHostName();
}
catch (UnknownHostException ex) {
}
jTextArea1.append("\\nNavn på server" + ":" + " " + serverName + "\\n");
/**HostNavn Adresen Fra den Locale Maskine Slut*/
}
public void jButton4_mouseClicked(MouseEvent e) {
{
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = null;
try {
builder = factory.newDocumentBuilder();
}
catch (ParserConfigurationException ex) {
}
Document document = builder.newDocument();
String besked = "<ChatPakke>" +
"<Afsender>" + "Server Delen" + "</Afsender>" +
"<Besked>" + "HEJMEDDIG" + "</Besked>" +
"<Kommando>" + "Kommando" + "</Kommando>" +
"</ChatPakke>";
StringBufferInputStream stream1 = new StringBufferInputStream(besked);
try {
document = builder.parse(stream1);
}
catch (IOException ex3) {
}
catch (SAXException ex3) {
}
TransformerFactory tFactory1 = TransformerFactory.newInstance();
Transformer transformer1 = null;
try {
transformer1 = tFactory1.newTransformer();
}
catch (TransformerConfigurationException ex1) {
}
DOMSource source1 = new DOMSource(document);
StreamResult result1 = null;
try {
result1 = new StreamResult(TraadForbindelse1.GetSocket().getOutputStream());
}
catch (IOException ex4) {
}
try {
transformer1.transform(source1, result1);
try {
TraadForbindelse1.GetSocket().getOutputStream().flush();
}
catch (IOException ex5) {
}
}
catch (TransformerException ex2) {
}
//PrintWriter out = TraadForbindelse1.GetPrintWriterOut();
//out.println("Server: " + jTextArea4.getText() + "\\n");
jTextField2.setText("");
}
}
public void mysql()
{
{
try {
Class.forName("com.mysql.jdbc.Driver");
}
catch (ClassNotFoundException ex) {
}
try {
forb = (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/javachatdatabase", "root" , "password");
}
catch (SQLException ex1) {
}
if (forb != null) {
jTextArea1.append("Der er forbindelse til Databasen JavaChatDataBase\\n");
}
if (forb == null) {
jTextArea2.append("Der er IKKE forbindelse til Databasen\\n");
jTextArea2.append("Forkert brugernavn\\n");
jTextArea2.append("...eller forkert...\\n");
jTextArea2.append("Forkert brugernavn\\n");
}
}
}
public void ViewConnectede()
{
/**Sletter jTextarea4 hver gang er trykkes, og så begynder nederstående - Logging*/
jTextArea4.setText("");
if (forb != null) {
Statement stmt = null;
try {
stmt = forb.createStatement();
}
catch (SQLException ex3) {
}
try {
stmt.executeUpdate("INSERT INTO logging (IP, Brugernavn, Klientrnavn, StartDato, StartTid, SlutDato, SlutTid) VALUES " + "('" + "190.160.130.100" + "', '" + "BrugerNavn" + "', '" + "Klientrnavn" + "', '" + df1.format(time) + "', '" + df2.format(time) + "', '" + df1.format(time) + "', '" + df2.format(time) + "'" + ");");
}
catch (SQLException ex4) {
}
try {
stmt = forb.createStatement();
}
catch (SQLException ex) {
}
ResultSet rs = null;
try {
rs = stmt.executeQuery("SELECT * FROM logging");
}
catch (SQLException ex2) {
}
try {
while (rs.next()) {
jTextArea4.append("Id :" + rs.getString("id") + "\\n");
jTextArea4.append("IP :" + rs.getString("IP") + "\\n");
jTextArea4.append("Brugernavn :" + rs.getString("Brugernavn") + "\\n");
jTextArea4.append("Klientnavn :" + rs.getString("Klientrnavn") + "\\n");
jTextArea4.append("Start Dato :" + rs.getString("Startdato") + "\\n");
jTextArea4.append("Slut Tid :" + rs.getString("Starttid") + "\\n");
jTextArea4.append("Sart Dato :" + rs.getString("Startdato") + "\\n");
jTextArea4.append("Slut Tid :" + rs.getString("Sluttid") + "\\n");
}
}
catch (SQLException ex1) {
}
}
}
public void ServerTrafik()
{
/**Sletter jTextarea4 hver gang er trykkes, og så begynder nederstående - trafik*/
jTextArea4.setText("");
if (forb != null) {
Statement stmt = null;
try {
stmt = forb.createStatement();
}
catch (SQLException ex3) {
}
try {
stmt.executeQuery(" INSERT INTO trafik (IP, Servernavn, StartDato, StartTid, SlutDato, SlutTid) VALUES " + "('" + localMachineIP + "', '" + serverName + "', '" + df1.format(time) + "', '" + df2.format(time) + "','" + df1.format(time) + "', '" + df2.format(time) + "');");
}
catch (SQLException ex4) {
}
try {
stmt = forb.createStatement();
}
catch (SQLException ex) {
}
ResultSet rs = null;
try {
rs = stmt.executeQuery("SELECT * FROM trafik");
}
catch (SQLException ex2) {
}
try {
while (rs.next()) {
jTextArea4.append("Id :" + rs.getString("id") + "\\n");
jTextArea4.append("IP :" + rs.getString("IP") + "\\n");
jTextArea4.append("Servernavn :" + rs.getString("Servernavn") + "\\n");
jTextArea4.append("Start Dato :" + rs.getString("Startdato") + "\\n");
jTextArea4.append("Slutt Tid :" + rs.getString("Sluttid") + "\\n");
jTextArea4.append("Start Dato :" + rs.getString("Startdato") + "\\n");
jTextArea4.append("Slut Tid :" + rs.getString("sluttid") + "\\n");
}
}
catch (SQLException ex1) {
}
}
}
public void jButton1_mouseClicked(MouseEvent e) {
startserver();
mysql();
}
public void jButton3_mouseClicked(MouseEvent e) {
System.exit(0);
}
public void jButton3_actionPerformed(ActionEvent e) {
}
public void jButton2_mouseClicked(MouseEvent e) {
jTextArea1.append("\\nPort:" + " " + portnummerIndtast + " " + "Er lukket.\\n");
}
public void jButton7_mouseClicked(MouseEvent e) {
jTextArea4.setText("");
}
public void jButton5_mouseClicked(MouseEvent e) {
if (forb == null) {
jTextArea1.append("Der er IKKE forbindelse til SQL Data Basen\\n");
}
else if(forb != null)
{
ViewConnectede();
}
}
public void jButton6_mouseClicked(MouseEvent e) {
ServerTrafik();
}
}
class ServerGUIFrame_jButton6_mouseAdapter
extends MouseAdapter {
private ServerGUIFrame adaptee;
ServerGUIFrame_jButton6_mouseAdapter(ServerGUIFrame adaptee) {
this.adaptee = adaptee;
}
public void mouseClicked(MouseEvent e) {
adaptee.jButton6_mouseClicked(e);
}
}
class ServerGUIFrame_jButton5_mouseAdapter
extends MouseAdapter {
private ServerGUIFrame adaptee;
ServerGUIFrame_jButton5_mouseAdapter(ServerGUIFrame adaptee) {
this.adaptee = adaptee;
}
public void mouseClicked(MouseEvent e) {
adaptee.jButton5_mouseClicked(e);
}
}
class ServerGUIFrame_jButton7_mouseAdapter
extends MouseAdapter {
private ServerGUIFrame adaptee;
ServerGUIFrame_jButton7_mouseAdapter(ServerGUIFrame adaptee) {
this.adaptee = adaptee;
}
public void mouseClicked(MouseEvent e) {
adaptee.jButton7_mouseClicked(e);
}
}
class ServerGUIFrame_jButton2_mouseAdapter
extends MouseAdapter {
private ServerGUIFrame adaptee;
ServerGUIFrame_jButton2_mouseAdapter(ServerGUIFrame adaptee) {
this.adaptee = adaptee;
}
public void mouseClicked(MouseEvent e) {
adaptee.jButton2_mouseClicked(e);
}
}
class ServerGUIFrame_jButton3_actionAdapter
implements ActionListener {
private ServerGUIFrame adaptee;
ServerGUIFrame_jButton3_actionAdapter(ServerGUIFrame adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton3_actionPerformed(e);
}
}
class ServerGUIFrame_jButton1_mouseAdapter
extends MouseAdapter {
private ServerGUIFrame adaptee;
ServerGUIFrame_jButton1_mouseAdapter(ServerGUIFrame adaptee) {
this.adaptee = adaptee;
}
public void mouseClicked(MouseEvent e) {
adaptee.jButton1_mouseClicked(e);
}
}
class ServerGUIFrame_jButton3_mouseAdapter
extends MouseAdapter {
private ServerGUIFrame adaptee;
ServerGUIFrame_jButton3_mouseAdapter(ServerGUIFrame adaptee) {
this.adaptee = adaptee;
}
public void mouseClicked(MouseEvent e) {
adaptee.jButton3_mouseClicked(e);
}
}
class ServerGUIFrame_jButton4_mouseAdapter
extends MouseAdapter {
private ServerGUIFrame adaptee;
ServerGUIFrame_jButton4_mouseAdapter(ServerGUIFrame adaptee) {
this.adaptee = adaptee;
}
public void mouseClicked(MouseEvent e) {
adaptee.jButton4_mouseClicked(e);
}
}
==========================================
Min Server Tråd er:
==========================================
package servergui;
import java.net.ServerSocket;
import java.net.*;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.PrintWriter;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.DataInputStream;
class TraadForbindelse implements Runnable {
Socket clientSocket = null;
PrintWriter out = null;
JTextArea SystemBesked;
JTextArea FejlBesked;
JTextArea ModtagerBesked;
JTextField SendBeksed;
JTextField portnummer;
JTextArea MySqlBesked;
public TraadForbindelse(JTextArea SystemB, JTextArea FejlB, JTextArea ModtagerB, JTextField SendB, JTextField port, JTextArea MySqlB) {
SystemBesked = SystemB;
FejlBesked = FejlB;
ModtagerBesked = ModtagerB;
SendBeksed = SendB;
portnummer = port;
MySqlBesked = MySqlB;
//Object jTextField1 = null;
try {
jbInit();
}
catch (Exception ex) {
ex.printStackTrace();
}
}
public Socket GetSocket()
{
return clientSocket;
}
public PrintWriter GetPrintWriterOut()
{
return out;
}
public void run()
{
System.out.println("Test 1 - for at se om vi kommer her til");
ServerSocket minserver = null;
try {
minserver = new ServerSocket(Integer.parseInt(portnummer.getText()));
SystemBesked.append("\\nPort Nummer" + ":" + minserver);
//FejlBesked.append("\\nFeljBesked Felt\\n");
//ModtagerBesked.append("\\nModtagerBesked Felt\\n");
//SendBeksed.setText("SendBeksed Felt\\n");
//MySqlBesked.append("\\nMySqlBesked felt\\n");
}
catch (IOException e)
{
FejlBesked.append("Fejl 1" + "Could not listen on port:" + " " + portnummer.getText());
System.exit(-1);
}
/**Venter På At Klienten Skal Logge På - Satrt*/
MySqlBesked.append("\\nServer klar, Venter på forespørgelse...\\n");
try {
Socket connectionsocket = minserver.accept();
InetAddress client = connectionsocket.getInetAddress();
MySqlBesked.append("Klient IP :" + " " + client.getHostAddress() + " Forbundet til server.\\n");
BufferedReader input = new BufferedReader(new InputStreamReader(connectionsocket.getInputStream()));
}
catch (Exception e)
{
MySqlBesked.append("\\nFejl 2:" + e.getMessage());
}
/**Venter På At Klienten Skal Logge På - Slut*/
try {
clientSocket = minserver.accept();
}
catch (IOException e)
{
FejlBesked.append("Fejl 3" + "Accept failed::" + " " + portnummer.getText());
}
try {
out = new PrintWriter(clientSocket.getOutputStream(), true);
}
catch (IOException ex1)
{
}
BufferedReader in = null;
try {
in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
}
catch (IOException ex2)
{
}
String inputLine, outputLine;
try {
/**Læsrer fra Socket forbindelen*/
while ( (inputLine = in.readLine()) != null)
{
ModtagerBesked.append(inputLine + "\\n");
if (ModtagerBesked.equals("EXIT"))
{
break;
}
}
SystemBesked.append("Server Lukker og Slukker");
out.close();
in.close();
minserver.close();
}
catch (IOException ex)
{
}
}
private void jbInit() throws Exception
{
}
}
========================================================
Problemet er opstået efter jeg har lavet følgende i min tråd:
=======================================
/**Venter På At Klienten Skal Logge På - Satrt*/
MySqlBesked.append("\\nServer klar, Venter på forespørgelse...\\n");
try {
Socket connectionsocket = minserver.accept();
InetAddress client = connectionsocket.getInetAddress();
MySqlBesked.append("Klient IP :" + " " + client.getHostAddress() + " Forbundet til server.\\n");
BufferedReader input = new BufferedReader(new InputStreamReader(connectionsocket.getInputStream()));
}
catch (Exception e)
{
MySqlBesked.append("\\nFejl 2:" + e.getMessage());
}
/**Venter På At Klienten Skal Logge På - Slut*/
=======================================
Med Venlig Hilsen
Carsten Nielsen
[Redigeret d. 10/02-05 12:27:41 af Carsten Nielsen]