//TESTUE_SEVER using System; using System.IO; using System.Reflection; using System.Runtime.Remoting; namespace Akadia.TestUE_Server { class Program { static void Main(string[] args) { string strAppDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetModules()[0].FullyQualifiedName); string strConfigFile = strAppDir + "\\TestUE_Server.exe.Config"; RemotingConfiguration.Configure(strConfigFile); Console.WriteLine("Server running and waiting for request ..."); Console.WriteLine("Press [Enter] to shut down Server"); Console.ReadLine(); } } } //MYSERVER using System; using System.Data; using System.Data.SqlClient; namespace Akadia.MyServer { public class RemoteServer : MarshalByRefObject { public DataSet GetDataSet() { DataSet ds = null; string strConnect = "Data Source=LAPTOP-DRGMF8RJ;Initial Catalog=Test;Integrated Security=True"; SqlConnection conn = new SqlConnection(strConnect); try { conn.Open(); string strSQL = "SELECT * FROM TableTest"; SqlDataAdapter sda = new SqlDataAdapter(strSQL, conn); ds = new DataSet(); Console.WriteLine("Ah Yess"); sda.Fill(ds, "Customers"); } finally { conn.Close(); } return ds; } } } TEST_UE using System; using System.Data; using System.IO; using System.Runtime.Remoting.Channels; using System.Runtime.Remoting.Channels.Http; using System.Windows.Forms; using Akadia.MyServer; namespace TestUE { public partial class Form1 : Form { DataSet ds = new DataSet(); private bool loadFromXML = false; private string path = @"..\..\persons.xml"; DataGridViewRow currRow; public Form1() { InitializeComponent(); dataGridView1.ReadOnly = true; dataGridView1.MultiSelect = false; //dataGridView1.SelectionMode = FullRowSelect(); //Einstellung Desinger Fornehmen } private void loadXml_Click(object sender, EventArgs e) { if (dataGridView1.DataSource == null) { ds.ReadXml(path); dataGridView1.DataSource = ds; dataGridView1.DataMember = "Person"; loadFromXML = true; } } private void SaveAsXML_Click(object sender, EventArgs e) { if (loadFromXML) { ds.WriteXml(path); return; } else { Console.Write("Not Implemented yet"); } } private void axInkEdit1_Change(object sender, EventArgs e) { string temp = axInkEdit1.Text; currRow.Cells[2].Value = temp; } private void dataGridView1_MouseClick(object sender, MouseEventArgs e) { DataGridViewSelectedRowCollection rows = dataGridView1.SelectedRows; //da wir nur einen Ausgewählten wert haben, können wir den ersten Index verwenden; currRow = dataGridView1.Rows[rows[0].Index]; axInkEdit1.Text = currRow.Cells[2].Value.ToString(); } private void LoadServer_Click(object sender, EventArgs e) { HttpChannel ch = new HttpChannel(8088); ChannelServices.RegisterChannel(ch); try { RemoteServer dss = (RemoteServer)Activator.GetObject(typeof(RemoteServer), "http://localhost:08086/MyServer/RemoteServer.soap"); ds = dss.GetDataSet(); dataGridView1.DataSource = ds.Tables[0]; } catch(Exception ex) { Console.WriteLine(ex.ToString()); } } private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) { } } } //SERVER public class Server { public static ServerSocket socket = null; public static void main(String[] args) { try { socket = new ServerSocket(1111); // maximal 65536 while (true) { Socket client = socket.accept(); ClientThread ct = new ClientThread(client); ct.start(); } } catch (IOException ex) { ex.printStackTrace(); } } } //MAIN public class Main { public static void main(String[] args) { Client client = new Client("test"); client.start(); } } //CLIENT import java.io.*; import java.net.Socket; public class Client extends Thread { private String clientName; public Client(String name){ this.clientName = name; } @Override public void run() { try { Socket socket = new Socket("127.0.0.1", 1111); OutputStream out = socket.getOutputStream(); ObjectOutputStream objectOut = new ObjectOutputStream(out); InputStream in = socket.getInputStream(); ObjectInputStream objectIn = new ObjectInputStream(in); //connect objectOut.writeUTF("connect"); objectOut.flush(); //send data Data xmlData = new Data(); objectOut.writeObject(xmlData); objectOut.flush(); System.out.println(objectIn.readUTF()); //disconnect objectOut.writeUTF("disconnect"); objectOut.flush(); System.out.println(objectIn.readUTF()); socket.close(); } catch (IOException e) { e.printStackTrace(); } } } //CLIENTTHREAD import java.io.*; import java.net.Socket; public class ClientThread extends Thread { private Socket socket; public ClientThread(Socket serverSocket) { this.socket = serverSocket; } @Override public void run() { try { OutputStream out = socket.getOutputStream(); ObjectOutputStream objectOut = new ObjectOutputStream(out); InputStream in = socket.getInputStream(); ObjectInputStream objectIn = new ObjectInputStream(in); String s; while (!(s = objectIn.readUTF()).equals("disconnect")) { if (s.equals("connect")) { System.out.println(s); Data data = (Data) objectIn.readObject(); data.printEmloyees(); System.out.println("\n\n"); printHTML(data); objectOut.writeUTF("server received data"); objectOut.flush(); } } System.out.println(s); objectOut.writeUTF("disconnected"); objectOut.flush(); } catch (IOException | ClassNotFoundException e) { e.printStackTrace(); } } private void printHTML(Data data) { System.out.println("Content-Type: text/html \n"); System.out.println(""); System.out.println("Hello World"); System.out.println(""); data.getAllEmployee().forEach(employee -> { System.out.println("

" + employee.getId() + "

"); System.out.println("

" + employee.getFirstname() + "

"); System.out.println("

" + employee.getLastname() + "

"); System.out.println("

" + employee.getLocation() + "

"); /*data.getAllExercises().forEach(exercises -> { //!!!!System.out.println("

" + exercises + "

"); }*/ System.out.println("
"); }); System.out.println(""); System.out.println(""); } } //DATA import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; import org.xml.sax.SAXException; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import java.io.File; import java.io.IOException; import java.io.Serializable; import java.util.ArrayList; public class Data implements Serializable { private String filename = "data.xml"; private ArrayList allEmployee; public ArrayList getAllEmployee() { return allEmployee; } public Data() { this.allEmployee = new ArrayList<>(); getXmlData(); printEmloyees(); System.out.println(); } public void getXmlData() { Document document = createDocument(); NodeList nodeListEmployee = document.getElementsByTagName("employee"); //Alle Employee Tags durchgehen for (int i = 0; i < nodeListEmployee.getLength(); i++) { Node node = nodeListEmployee.item(i); //employee Element element = (Element) node; String id = element.getAttribute("id"); String firstname = element.getElementsByTagName("firstName").item(0).getTextContent(); String lastname = element.getElementsByTagName("lastName").item(0).getTextContent(); String location = element.getElementsByTagName("location").item(0).getTextContent(); ArrayList allExercises = new ArrayList<>(); NodeList nodeListExercise = document.getElementsByTagName("exercises"); //Alle Exercises durchgehen for (int j = 0; j < nodeListEmployee.getLength(); j++) { NodeList childExercise = nodeListExercise.item(j).getChildNodes(); for (int k = 0; k < childExercise.getLength(); k++) { //String exercise = element.getElementsByTagName("exercise").item(j).getTextContent(); Node current = childExercise.item(k); String s = current.getTextContent(); System.out.println(s); allExercises.add(s); } } //add to list Employee e = new Employee(id, firstname, lastname, location, allExercises); allEmployee.add(e); } } public Document createDocument() { try { File file = new File(filename); DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); Document document = documentBuilder.parse(file); return document; } catch (ParserConfigurationException | IOException | SAXException e) { e.printStackTrace(); } return null; } public void printEmloyees(){ for (Employee e : allEmployee){ System.out.println(e.toString()); } } } //EMPLOYEE import java.io.Serializable; import java.util.ArrayList; public class Employee implements Serializable { private String id; private String firstname; private String lastname; private String location; private ArrayList exercises; public Employee(String id, String firstname, String lastname, String location, ArrayList exercises) { this.id = id; this.firstname = firstname; this.lastname = lastname; this.location = location; this.exercises = exercises; } public String getId() { return id; } public String getFirstname() { return firstname; } public String getLastname() { return lastname; } public String getLocation() { return location; } public ArrayList getExercises() { return exercises; } @Override public String toString() { return "Employee{" + "id='" + id + '\'' + ", firstname='" + firstname + '\'' + ", lastname='" + lastname + '\'' + ", location='" + location + '\'' + ", exercises=" + exercises + '}'; } }