» »

[Java]Client/Server preko socketa

[Java]Client/Server preko socketa

KernelPanic ::

Spostovani!

Prosil bi vas za malo pomoci pri naslednjem tasku:
Namrec, narediti moram client applikaicjo (v Swingu) ter server (konsola), ki bosta povezana preko socketa. Swing klient se mi ze poveze na streznik preko socketa in do tu je vse ok. Vendar sem sedaj naletel na tezavo: Namrec, kako naj client aplikacijo sprogramiram, da bo v locenem threadu poslusala za promet in ko bo promet od streznika, da podatke prevzame in jih ta thread nato poslje swing threadu, da podatke prikazem v Swing graficnemu vmesniku? Kako naj se tega lotim?

Lp,
Marko

kr?en ::

Si probal kdaj s JMS?

GupeM ::

Tukaj? ali mogoče tukaj?

kr?en ::

Nice, se bolj enostavna resitev :D

KernelPanic ::

GupeM je izjavil:

Tukaj? ali mogoče tukaj?
Za tale GUI client, ki si mi dal link, so samo jar-i na voljo, brez sourcev ...

GupeM ::

KernelPanic je izjavil:

GupeM je izjavil:

Tukaj? ali mogoče tukaj?
Za tale GUI client, ki si mi dal link, so samo jar-i na voljo, brez sourcev ...

Na pogled mi je zelo podoben. Nisem pa preverjal če je uporabno. Bil je samo prvi rezultat na googlu.

KernelPanic ::

Ok, decki!

Sem vzel referenco in naredil client+gui ter server side in komunikacija med njima sedaj lepo dela. Sedaj imam novo tezavo. Iz klienta posljem komando serverski aplikaciji za zajem podatkov in v spodnji kodi (client side) podatke tudi uspesno dobim, saj se mi vector nafila:
    class CClientThread extends Thread
    {
        @Override
        public void run()
        {
            while(true)
            {
                try
                {
                    Object obj=ois().readObject();

                    if(gui()==null)
                    {
                        System.out.println(obj.toString());
                    }
                    else
                    {
                        if(obj instanceof CInstance)
                        {
                            CInstance instance=(CInstance)obj;

                            gui().panelStatus().statusArea().append("Server sent instance information: "+
                                    instance.id()+
                                    " "+
                                    instance.name()+
                                    " "+
                                    instance.host()+
                                    " "+
                                    instance.dbPort());
                            instances().add((CInstance)obj);

                            DefaultListModel model=(DefaultListModel)gui().panelMain().panelInputParameters().lInstances().getModel();
                            model.addElement(instance.name());
                        }

                        if(obj instanceof CMeetingsHostsAttendees)
                        {
                            CMeetingsHostsAttendees mha=(CMeetingsHostsAttendees)obj;
                            gui().mha().add(mha);
//                            System.out.println(mha.id()+
//                                    " "+
//                                    mha.meetingId()+
//                                    " "+
//                                    mha.strMeetingName()+
//                                    " "+
//                                    mha.lastName()+
//                                    " "+
//                                    mha.firstName()+
//                                    " "+
//                                    mha.lastName()+
//                                    " "+
//                                    mha.dtFrom()+
//                                    " "+
//                                    mha.dtTo());
//                            System.out.println("mha size:"+mha().size());
                        }
                    }
                }
                catch(Exception ex)
                {
                    break;
                }
            }
        }
Ko pa v GUI delu klienta hocem iz the podatkov narediti datasource za jasperreports:
    public void actionPerformed(ActionEvent e)
    {
        if(e.getSource().equals(this.panelMain().panelInputParameters().btnGo()))
        {
            try
            {
                this.mha().clear();
                this.client().sendCommand(new CCommand(ECommands.FETCH_MEETINGSHOSTATTENDEES.toString()));
                JRBeanCollectionDataSource datasource=new JRBeanCollectionDataSource(this.mha());   // TUKAJ HOCEM NAREDITI DATASOURCE IZ VEKTORJA, KI SEM GA NAFIALAL V THREADU

                System.out.println("this.mha() size:"+this.mha().size());
                System.out.println("JRBeanCollectionDataSource datasource record count:"+datasource.getRecordCount());

                HashMap parameters=new HashMap();
                parameters.put("dtFrom",
                        this.panelMain().panelInputParameters().dtFrom().getValue());
                parameters.put("dtTo",
                        this.panelMain().panelInputParameters().dtTo().getValue());
                parameters.put("instanceName",
                        this.panelMain().panelInputParameters().lInstances().getSelectedValue().toString());
                this.panelMain().panelReport().setReportPrint(JasperFillManager.fillReport("D:\\BillingClient\\reports\\ReportHosts.jasper",
                    parameters,
                    /*new JREmptyDataSource()*/datasource));
                this.panelMain().panelReport().setReportViewer(new JRViewer(this.panelMain().panelReport().reportPrint()));

                this.panelMain().panelReport().add(this.panelMain().panelReport().reportViewer(),
                    BorderLayout.CENTER);
                this.panelMain().panelReport().updateUI();
            }
            catch(Exception ex)
            {
                ex.printStackTrace();
            }
        }
, mi v vrstici z slovenskim komentarjem, launcha sledec execption:
java.util.ConcurrentModificationException
at java.util.AbstractList$Itr.checkForComodification(AbstractList.java:372)
at java.util.AbstractList$Itr.next(AbstractList.java:343)
at net.sf.jasperreports.engine.data.JRBeanCollectionDataSource.next(JRBeanCollectionDataSource.java:87)
at net.sf.jasperreports.engine.fill.JRFillDataset.advanceDataSource(JRFillDataset.java:1380)
at net.sf.jasperreports.engine.fill.JRFillDataset.next(JRFillDataset.java:1229)
at net.sf.jasperreports.engine.fill.JRFillDataset.next(JRFillDataset.java:1208)
at net.sf.jasperreports.engine.fill.JRBaseFiller.next(JRBaseFiller.java:1554)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReport(JRVerticalFiller.java:149)
at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:909)
at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:841)
at net.sf.jasperreports.engine.fill.JRFiller.fill(JRFiller.java:88)
at net.sf.jasperreports.engine.JasperFillManager.fill(JasperFillManager.java:653)
at net.sf.jasperreports.engine.JasperFillManager.fill(JasperFillManager.java:569)
at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:915)
at gui.main.CFrameMain.actionPerformed(CFrameMain.java:120)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
at java.awt.Component.processMouseEvent(Component.java:6297)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3275)
at java.awt.Component.processEvent(Component.java:6062)
at java.awt.Container.processEvent(Container.java:2039)
at java.awt.Component.dispatchEventImpl(Component.java:4660)
at java.awt.Container.dispatchEventImpl(Container.java:2097)
at java.awt.Component.dispatchEvent(Component.java:4488)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4575)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4236)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4166)
at java.awt.Container.dispatchEventImpl(Container.java:2083)
at java.awt.Window.dispatchEventImpl(Window.java:2489)
at java.awt.Component.dispatchEvent(Component.java:4488)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:674)
at java.awt.EventQueue.access$400(EventQueue.java:81)
at java.awt.EventQueue$2.run(EventQueue.java:633)
at java.awt.EventQueue$2.run(EventQueue.java:631)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:98)
at java.awt.EventQueue$3.run(EventQueue.java:647)
at java.awt.EventQueue$3.run(EventQueue.java:645)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:644)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
Mi lahko kdo pomaga pri tej napaki?

KernelPanic ::

Pardon, ne vsuje se pri kreaciji datasourca, ampak v vrstici:
                this.panelMain().panelReport().setReportPrint(JasperFillManager.fillReport("D:\\BillingClient\\reports\\ReportHosts.jasper",
                    parameters,
                    /*new JREmptyDataSource()*/datasource));

kr?en ::

http://docs.oracle.com/javase/1.5.0/doc...

Po domace, spreminjas listo skozi katero v istem trenutku iteriras.

KernelPanic ::

kr?en je izjavil:

http://docs.oracle.com/javase/1.5.0/doc...

Po domace, spreminjas listo skozi katero v istem trenutku iteriras.
To razumem, sem pogledal, ampak kje hudica? A je mozno, da moram ob koncu prenosa blokirati thread?


Vredno ogleda ...

TemaSporočilaOglediZadnje sporočilo
TemaSporočilaOglediZadnje sporočilo
»

Programiranje problem android

Oddelek: Programiranje
51173 (938) g333kk
»

android črta

Oddelek: Programiranje
412399 (1670) g333kk
»

[Netbeans-Java]Embossing,blurring,sharpening

Oddelek: Programiranje
71134 (1036) t3hn0
»

tomcat in datasource

Oddelek: Programiranje
131994 (1751) infiniteLoop
»

Težava z zagonom ldap serverja

Oddelek: Operacijski sistemi
81260 (1206) kopernik

Več podobnih tem