Class files downloaded from the network and the implementation of

  Abstract: The class files downloaded from the network and the implementation of 

  </ Td> </ tr> <tr> <td height="35" valign="top" class="ArticleTeitle"> 

  Import java.net .*; import java.lang.reflect .*; public class MyURL (static public void main (String args []) throws Exception (URL myurl [] = (/ / type of document addresses, in order to verify, please release to the web server such as: http://127.0.0.1:8080/cwbwebhome/ new URL ( "file: / / / C: / CH3/ClassLoader/web /"), new URL ( "http://127.0.0.1: 8080/cwbwebhome / ")); URLClassLoader x = new URLClassLoader (myurl); Class c = x.loadClass (" TestURL ");// loading class files TestURL.class Class getArg1 [] = ((new String [1]) . getClass ()) / / main () method of the main parameters of type Method m = c.getMethod ( "main", getArg1); / / Get the main method my1 String [] = ( "arg1 passed," "arg2 passed" ) / / Call the main method of the parameters Object myarg1 [] = () my1; m.invoke (null, myarg1) / / call TestURL main method of static Object ob = c.newInstance (); / / object of a TestURL Class arg2 [] = null; Method m2 = c.getMethod (the "tt", arg2); / / call TestURL category of non-parametric method tt () m2.invoke (ob); Class arg3 [] = ((new String ()). getClass (), int.class); Method m3 = c.getMethod (the "tt", arg3); Object myarg2 [] = ( "Arg1" new Integer (100)); m3.invoke (ob, myarg2) / / call TestURL category method tt (String s, int i))) Running Results (jdk1.5 through): C: \ java> java MyURL From Main arg1 passed arg2 passed From tt without args Fron tt with args Arg1 100 C: \ java> of TestURL.java import java.io. *; public class TestURL (static public void main (String args []) throws Exception (System.out.println ( "From Main"); System. out.println (args [0]); System.out.println (args [1]);) public void tt () throws Exception (System.out.println ( "From tt without args"); byte b = [] "How are you!." getBytes ( "UTF8"); FileOutputStream f = new FileOutputStream ( "ssss.txt"); f.write (b);) public void tt (String s, int i) (System.out. println ( "Fron tt with args"); System.out.println (s); System.out.println (i);)) 

  </ Td> </ tr> <tr> 

  ↑ Back 

Java: embedded in the core network

  Abstract: Java: embedded in the core network 

  Although some on the market today embedded solution does not require network access, but the era of independent equipment is gradually dying out.    With Internet telephony, Internet television, smart cards, and personal digital assistants, and other innovative devices embedded in a large number, and the growing need for network customer identification system, and those who allow them to insert and access various services standard, that is, at any time, any place and Based on any platform, and the realization of any person connected. 

  And desktop systems, consumer devices use a variety of user interface technology, storage space and a relatively small screen specifications, and configure embedded processor, energy consumption, user response time and physical space, and other areas were severely restricted.    Consumer devices must be independent and not run on a system management functions environment.    In view of this, and consumer equipment failure can not.    Java platform has many characteristics of this type of equipment makes it an ideal choice.    Dynamic Link and loading characteristics, allowing remote software updates and patches, as Java byte code than the small machine code, the code need only minimal storage space; Java programming language is object-oriented language that allows modular code and multi-purpose, all the application code does not require a permanent presence in the equipment to use the Java platform, code can be downloaded only when necessary to equipment; Java application environment safe and reliable characteristics (including the elimination of the guide, direct memory access, border checkpoints to prevent illegal dumping and stack overflow), will ensure that no unauthorized objects from consumer devices in the local memory read and write data or code. 

  Currently, Sun offers a complete embedded Java solutions, including PersonalJava, EmbeddedJava and Java Card Application Programming Interface (API), they were applied to different applications environment. 

PersonalJava

  PersonalJava platform is designed for the individual consumer devices and networking applications designed for home, office and mobile users.    Configuration of a variety of display technologies such as television equipment, and usually not the keyboard or mouse input and the implementation of navigation products can be used PersonalJava platforms. 

  PersonalJava is a Java application environment (JAE), which by the Java Virtual Machine and Java application programming interface subset of the components, including both core and optional application programming interface and libraries.    In addition, PersonalJava application programming interface also includes consumer applications in the environment of limited resources demand for properties.    PersonalJava application programming interface and application programming interface EmbeddedJava share a common core group application programming interface, we can run small programs, and support relatively sophisticated visual displays, but also networking.    PersonalJava application environment applicable to the equipment, including mobile handheld devices, set-top devices, game console and the smart phone. 

  PersonalJava platform includes the following components: 

  Java Virtual Machine: bytecode interpreter, byte code inspection, loading category, as well as Unicode text support, 32-bit and 64-bit integer, garbage collection, multi-dimensional arrays, floating-point operations, threads, exception handling features; 

  Demand Java categories: input / output, language support, application; 

  Internationalization (I18N) support: product use software buns in a comprehensive set so that only developers choose to support only the language, thereby reducing space and memory usage; 

  Java Beans, Java applets, the network; 

  Support code signing (digital signature); 

  Consumer products to look and feel as the goal and made corresponding adjustments JavaAWT version.    It can provide graphics and window features, support for low-resolution display and optional input devices (through a mouse and keyboard equipment without incident expansion model to be achieved). 

  Each of Java application environment (JAE) by the core application programming interface and extend the standard (optional) application programming interface.    PersonalJava the hierarchical structure from low - to high-order: Java Virtual Machine, Math, input / output, language support, functional class library, international, Java Beans, network functions (NetWorking), Java Applets and AWT. 

  PersonalJava environment custom application development tools, including JavaCheck pre-processor, it can test the code and PersonalJava application environment consistency.    Other tools that will allow developers configure, compile and the creation of images, set up in the ROM executable code, implantation optional HTML, image, voice and data files. 

EmbeddedJava

  EmbeddedJava application environment for embedded devices designed.    Such equipment configuration dedicated and very limited storage space, and does not require general Web browsing.    EmbeddedJava application environment to provide a set of tools to allow developers to meet the needs of specific applications, configure and compile the necessary fields and includes only method of the environment, can be read-only memory in the system integrity of the environment for such formation and installation of executable image .    A developer can use the EmbeddedJava application environment to create a variety of products, including low-end mobile phones, pagers, process controller, test equipment, office printers and peripherals as well as network routers and switches. 

  EmbeddedJava applications to run in real-time operating environment, to suit the small storage space in the visual display equipment and diversification has been optimized processing.    EmbeddedJava application environment allows equipment manufacturers in its software products, use of the Java programming language portability and flexibility. 

  Configurability 

  When the storage space is severely limited the embedded device design software, in accordance with the application requirements configuration environment is a crucial factor.    If the device (such as pagers) does not require file system, not on the configuration file system support functions.    EmbeddedJava application programming interface provides a number of tools, the ability to achieve such a configuration.    If JavaFilter (TM) technology is generated in order to assess applications and application needs of the fields and methods table JavaCodeCompact will use the table, choose from a Java application environment specified fields and methods; JavaDataCompact can read static data, such as documents or images HTML documents; developers to use these tools, can be read-only memory (ROM) to install executable code, configuration, and even the compiler for images, it is estimated that the resources needed. 

  Performance 

  In the network routers and switches that run on one type of equipment embedded applications, the design goal is to the final product, and maintain the hardware provided by the real-time support.    In other words, these products require high performance.    Therefore, the application programming interface EmbeddedJava the purpose is to use real-time operating system.    Considered in the design of performance and transplantation factors. 

  Upward compatible applications 

  As long as the corresponding equipment support capabilities, and applications can EmbeddedJava PersonalJava (TM) and upward compatible with the Java platform, and run on these platforms. 

  EmbeddedJava compatibility 

  At present, the Sun is planning to develop a compatible programs is for the purpose of EmbeddedJava platform for achieving consistency.    Java platform certification process and the current process of the same. 

  Java Card 

  Java Card specifications for the Java technology in the smart card and the storage space is very limited and other equipment running created.    It offers platform independence, storage and the ability to update multiple applications, as well as with existing smart card standards compatibility, a growing number of smart card applications, excellent flexibility. 

  Java Card application programming interface allows for the preparation of a smart card platform applications, and Java card technology in any other such platforms to run on.    Java Card Application Environment (JCAE), the original equipment manufacturer basis, the smart card manufacturers to licensing, these manufacturers on behalf of the global smart card manufacturing capacity of more than 90%. 

  Java smart card technology has the following unique advantages: 

  Platform independence.    Java card with the Java API specification cards on the procedure will be run on JCAE developed by the use of the smart card, allowing developers to use the same Java Card small program from different vendors, running on smart cards. 

  Multi-application functions.    Can run multiple applications on a single smart card.    Java programming language to the inherent design of small downloadable code elements as the center, can be safe and reliable and convenient in a single smart card to run multiple applications. 

  Dynamic adaptability.    Smart card issuers, the application will install smart card issuers to provide a dynamic approach to customer needs change.    If the customer decided to change the smart card associated with the common procedure, the smart card issuer to meet its requirements, without issuing new cards. 

  Flexibility.    Java Card technology uses object-oriented methods, procedures for the preparation of smart cards to provide flexibility. 

  And the existing smart card standards compatibility.    Java Card application programming interface not only with the formal such as ISO7816 international standards compatibility, but also with Europay / MasterCard / Visa (EMV) for such a class of the industry standard compatible. 
  ↑ Back 

Network source told the International Chess

  Abstract: network source told the International Chess 

  : 666] 
  </ Td> </ tr> <tr> <td height="35" valign="top" class="ArticleTeitle"> <table width = "100%" border = "0" cellspacing = "0" cellpadding = " 0 "> <tr> <td width="431" height="86" align="center" valign="top"> 

  A network can be a battlefield of chess source.    This procedure can be for a pawn and board, and chat applet to run, and other functions, very good!    ! 

  One with ant-source compiler (all source files and directory structure download) 

  C: \ cs> ant compile 
  Buildfile: build.xml 

  Compile: 
  [Mkdir] Created dir: C: \ cs \ build 
  [Javac] Compiling 60 source files to C: \ cs \ build 
  [Javac] Note: * uses or overrides a deprecated API. 
  [Javac] Note: Recompile with-Xlint: deprecation for details. 
  [Javac] Note: Some input files use unchecked or unsafe operations. 
  [Javac] Note: Recompile with-Xlint: unchecked for details. 

  BUILD SUCCESSFUL 
  Total time: 14 seconds 

  Second, in order to activate service - 

  C: \ cs> java com.borland.samples.chess.server.ChessServer 
  05-12-28 22:44:43 CST 
  Read 2 userId records from C: \ cs \ users.obj 
  Hello 8889 
  Address of the Server: microsof-0f0cfb/127.0.0.1 
  HelloThread: Waiting for someone to talk to me on port 8889 

  Third, open two dos window, in order to activate the two clients, each client program will pop-up login dialog, please enter your name and password login.    If one of them 

  C: \ cs> java com.borland.samples.chess.client.ChessViewer 
  ImageName = images / cmpieces.gif 
  ImageName = images / owlpieces.gif 
  ImageName = images / ibmpieces.gif 
  No file specified 
  ImageFactory.square size pieces = 49 = 23671010 
  CV8889Received: 8890 
  ClientSender: Name with two parameters 
  ClientSender: List with parameters 0 
  ClientSender: AdjuornedList with parameters 0 

  Operation interface as follows. 
  In order to begin the game, the opponent's name first selected, then click on the "challenge challenge" button, and wait for the opponent battle. 

  </ Td> <td width="253" valign="top"> </ td> </ tr> <tr> <td height="20" colspan="2"> 

  </ Td> </ tr> </ table> 

  This procedure can be for a pawn and board 

  </ Td> </ tr> <tr> 

  ↑ Back 

How to prepare java network procedures, external machines to achieve a HTTP proxy to access the Internet through the machines. Feeling more complicated:)

  Abstract: How to prepare java network procedures, external machines to achieve a HTTP proxy to access the Internet through the machines.    Feeling more complicated:) 


  LAN customers a machine A, A through a HTTP proxy to access the Internet. 
  For various reasons, every day I have to go to customers where A machine operation, and some things in a very simple and a waste of a waste of time to waste money. 
  Now my thinking is: write a java client and server-side, of course, was put A client machine, the server-side, I put to the computer.    But the operation but it is one I used to operate server-side client, and then the client according to the input of the corresponding operating system calls (linux system) order. 
  I have already had some ideas, but to write about or feel more responsible, but I do not know what I am thinking right.    Therefore, in this view by the vast number of friends to see. 
  Ask one more question: Are there has achieved a function of this software? 






  Look 



  Very hard to keep it at 100, is so lost?  -_-|||



  You have fixed IP, and if so, to A machine connected to your machine is not on the line 



  's Computer fixed ip. 
  How?    A client machines through http agents, we can not simply connected, we must use http format package, but this is not a problem. 
  The problem is that the initiative can only be issued A machine connected, and the request is connected to End disconnect, this relatively depressed. 



  Pcanywhere software 


  ↑ Back 

Design constraints from traditional network P2P systems

  Abstract: from the restrictions of traditional P2P network system 

  : With the popularity of mobile computing and embedded microprocessor can be ubiquitous networking applications, TCP / IP has shown it has finally become obsolete.    Jxta design of the original intention was to break the current TCP / IP-based network restrictions, thus expanding the scope of the Internet can touch.    Jxta developerWorks in the discussion of this last of a series of articles, Sing Li example of this expansion of the system and to address a practical problem.    You will see Jxta from client / server network typical constraint limits.    Please click on the top or bottom of this discussion, in the discussion forum with the author and other readers to share experiences on paper. 

  To this series of articles here, we carefully inspected the Jxta, a reference Java Implementation of the new P2P platform is how to work.    In the first part, we know the Jxta interoperability features.    Jxta is defined as a group of interoperability agreement can be cross-hardware platform, operating system and programming language.    We also discussed the Jxta model and the operation of such machines include, and the group, and pipeline services, many of the important concepts.    In the second part, our focus is on the establishment and operation of Jxta.    We have examined the application of a Jxta - Jxta shell - and experienced a pipeline from the creation of an aircraft, such as sending a message to another machine, such as the case.    As we prepare to expand Jxta shell, the first time we have been using Jxta API programming experience.    So far, we have discussed Jxta is the way to the bottom.    For a system such as ours programming and network engineering background of the people, this is the natural. 

  In this series of Title III of this article that is the last one, we should not be reversed.    From those involved in the application-level design and architecture of the human point of view, this is a top-down view Jxta.    We have a specific examples of the problem, an analysis of this problem and design a solution to demonstrate how Jxta is the natural solution to the problem. 

  With this paper, we discuss how Jxta tied (juxtaposition) of the prospect of change in networking, we also provide a Jxta client services and the design and code. 

  Solve the problem of a distributed data collection idea what we need to create a large-scale meteorological data collection and analysis systems.    Under this system, we have hundreds of meteorological data collection point and each collection point with a miniature weather station, which will weather the current temperature (and other atmospheric conditions) to provide a focus-group data.    Collectors all over the world; these traps is not directly connected to the Internet, there may be no time to collect new data-linking of connectivity or released.    In this project, the involvement of the exact number of collectors often change; data analysis and processing based on regional average. 

  Only 10 at the beginning of concentrators.    Each concentrator surveillance from many of the data collection, real-time data is available to the relational database.    Subsequently, the data from the relational database was provided to the operation of the weather analysis and forecasting supercomputer simulation model by which dealt with.    On the number of devices and locations will be changed, but their behavior is mostly more stable.    Once installed, the focus will be maintained for operation unless encountered failure. 

  We must address the question: How can our system continued to operate, and can almost do not take into account the impact on the overall performance under the conditions, allowing dynamic add or remove the traps and concentrator. 

  Initial analysis: the complexity of a particular network in certain collection system can be directly access to the Internet; other through radio transmission technology to connect, at their worst in the external environment.    In fact, based on the radio in these traps, many are designed into energy, in order to extend battery life; for the effective collection of barely enough with a collection of recent contacts or base station.    Many of these traps do not support TCP / IP, but the use of the basic packet radio technology.    Some more independent only for the collection of solar panels on its access to energy, transport and use of satellite communications.    There are some other traps, it will connect to standard cellular phones, the use of SMS (short message service, short message service) messaging to send information. 

  In the entire project life cycle, can be used for the collection of the amount will be any change in the beginning of the project, we can not predict the future will be built on the collection of the connection type, can predict collected will be used for technology.    For example, at a certain stage of the project, a super computer clusters in the use of simulation software to simulate the huge number of traps.    Our solutions must be able to adapt to all the traps, whether it is true or simulation, the present or the future. 

  Solutions: Parallel (Juxtaposition) 
  Figure 1 shows used to solve the problem of a high-level design. 

  Figure 1. Solve the problem of data collection 

  IMG http://www-900.ibm.com/developerWorks/cn/java/j-p2pint/part3/fig1.gif [/ IMG] Please note that P2P networks tied to adapt to a variety of different networks, and concentrate on provides P2P networks and the traditional client / server network connectivity between the database server and supercomputer presence in the client / server network.    Concentrator to serve as the bridge between the two networks - with each focused on the P2P networks with dynamic characteristics of the client / server network with static characteristics. 

  This architecture reflects the Jxta the traditional system and the complementary roles of these traditional systems parallel to the value-added capabilities - through parallel (juxtaposition), Jxta derived from the name of the word. 

  We do not want to discuss here the depth client / server network details, and not because of the uniqueness of what we can even use VPN technology on the Internet run it.    Interesting part of the P2P network.    Figure 2 shows its composition, it can change with the changes in the future.    Please note which uses a variety of different techniques. 

  Figure 2. Data collection component of the network 

  IMG http://www-900.ibm.com/developerWorks/cn/java/j-p2pint/part3/fig2.gif [/ IMG] in achieving this P2P network, we can use Jxta to obtain the following advantages: 

  Easy to add or remove a new collection or concentrator, as a result of the unification of scattered Jxta addressable 

  Design simplicity, as a result of the virtual network Jxta 

  Continued operation, as a result of failure to support flexible Jxta 

  Maintenance-free operation, as a result of Jxta supports dynamic self-organizing network 

  Support across many hardware platforms and a variety of different programming languages to achieve support by the various communication protocols allow us to a more detailed look into several benefits, and see how Jxta architecture unique to the various aspects of the contribution. 

  Unity unified scattered addressable scattered addressing the literal meaning, and the machine can generate an ID for themselves and immediately joined to the network, rather than with any registered person or central certification body contact, and today's DNS must be so.    This feature at any time so that we can add to the network of collectors and concentrated. 

  In this paper package with the code (you can download it from the reference), we provide practical called mdidgen procedures, it can be used for the new services and channels Jxta generated addresses.    (To learn more about mdidgen, please refer to notes mdidgen utility.) You can read this series of articles I understand how Jxta ID is used to Jxta object (for example: the machine, etc., and the group, services and Pipeline) unified addressable. 

  Please note that Jxta in the network, such as the machine does not have to be an independent physical existence.    In our example, we use a super computer to simulate a huge number of clusters for the collection, each with its own collection of the unified address.    Simulation of these traps each other in the P2P network is a part of it and those who have the physical presence of the machine there is no difference, and so on and so on the plane. 

  Through a decentralized network of virtual addressing and for all collectors to focus on network-the only logo, they immediately become on the network, such as machine and began to communicate with each other.    Although they may be through many different types of messaging mechanism interrelated, but in Jxta level, they are only a virtual network nodes in the network, as shown in Figure 3. 

  Figure 3. Network virtualization 

  IMG http://www-900.ibm.com/developerWorks/cn/java/j-p2pint/part3/fig3.gif [/ IMG] Please note, and will be collected for the machine, such as the actual linked up with each other all the different transmission and addressing modes are virtual, leaving only a mesh network, each of which, such as machines and other machines, such as one pair of each link.    Jxta addressable through the use of unified models and bind very late (very late binding), in a number of agreements to add endpoint of the intelligent routing of information to accomplish this.    In essence, each agreement or an endpoint transmission protocol stacks have become a virtual Jxta network drivers, will be mapped to virtual network on the physical network.    Figure 4 shows such settings. 

  Figure 4. Endpoint agreement as a driver 

  IMG http://www-900.ibm.com/developerWorks/cn/java/j-p2pint/part3/fig4.gif [/ IMG] communication protocol to become qualified endpoint agreement, it will only need two physical nodes between XML messages sent or received.    Transmission reliability or news on the radio did not support any demands.    Thus, the simplest packet radio agreements can also be used for endpoint protocol drivers, like TCP / IP protocol such a complex multi-tied.    This also explains why HTTP and TCP / IP protocol stack, in Jxta is the same endpoint-level agreements, despite their very different physical level.    HTTP is an endpoint supported by the agreement, for as long as necessary, it can be as much as possible through the firewall, thus acquiring a Jxta from the machine to another, such as news. 

  Jxta each in the network, such as the machine can simultaneously support multiple endpoint agreement, Jxta virtual network mechanism will be in a manner as possible no later than the unity of the virtual network address mapped to the physical network addresses (called network endpoint Jxta ).    In essence, such as an aircraft corresponds to a group of physical endpoint, the endpoint of each physics can be completely different from the physical communications protocol to achieve.    Higher level of service routing and virtual hide this point.    Many people may be able to see that this is a multi-protocol router in the form of very senior - this is the same equipment to become a reality in today's Internet.    The development of this concept will bring us to a more general Internet, it is natural and simple. 

  Let us look in more detail Figure 5 shows examples.    A machine such as the network is a collection, it tried to collect through a series of intermediaries (such as for the B, C and D) will be sent to concentrate on its data (such as on-E).    Each of the plans, such as machine Below is the reciprocal of a group supported by the agreement. 

  Figure 5. Jxta routing examples 

  IMG http://www-900.ibm.com/developerWorks/cn/java/j-p2pint/part3/fig5.gif [/ IMG] because of the machine, such as A is not directly connected to the machine, such as E, its news must be through an intermediary such as machine on the B, C and D routing.    Jxta will automatically routing of messages: 

  Using TCP / IP on an equal plane from A to B on an equal plane 

  Use packet radio from the agreement, such as B-to-C, and so on 

  From the right, such as the use of SMS-C to D on an equal plane 

  HTTP on the use of such machines from D to E on an equal plane 
  E, and so on-will be created in its pipeline from the receiving machine, etc. A news Jxta totally not aware of the complexity of the implementation of its work.    Please note, and the C - to-D, and so on the path of non-symmetrical; Jxta is designed specifically to address this situation.    If there is news from the machine, such as E sent back to the machine, such as A, Jxta PPP dial-up modems will be used automatically from the machine, such as routing to D-C, and so on. 

  Despite the failure described above flexible routing function has been very surprising, but what is more important is that Jxta must be able to fit the evolving P2P network topology.    In particular, it must be able to handle as routing information, such as the agent of P2P inherent unreliability.    In our example, if the relay can not be used for the collection, then another collector to rely on the routing information for the collection will not be able to communicate. 

  When the machine, such as joining or leaving the network, Jxta real-time information to be able to re-routing.    Figure 5 to consider the routing examples.    Please imagine that, due to certain reasons, such as in the machine A has been sent to news (currently transmission) have not yet reached the aircraft, such as C, and so on and so on for C and D between the machine is broken satellite link .    Jxta must be able to dynamically through some alternative path (probably by another group of intermediate nodes) to the news re-routing of aircraft, such as E.    This dynamic re-routing is based on the greatest efforts (best-effort) completed; occasionally this is the case, if there is no possible route (unless the intermediary transmission lasting support queue), the information may be lost.    As a result of this re-routing can be used to change the actual arrival of the aircraft, such as E endpoint agreement (for example: HTTP to the TCP / IP), therefore, we should have reached the final routing hops, such as machine to the physical endpoint The bonding will occur.    This is a very late Jxta binding nature. 

  In the group, such as level (please refer to the first of this series of articles about the group, such as more knowledge), Jxta through the support of the group and other services - such as in the group are always available, redundancy to achieve service — Support fault flexibility. 

  Dynamic self-organizing network when a unified virtual network ID, such as machine on the network inserted into Jxta, it must do from my guide: 

  , And other local positioning of the machine and found that they function 

  Can be found, such as the right to join a group and 

  Found that the group, such as the services available and we start to use them from the second article in this series in that it is in the news all levels through the issuance, repeaters, intermediary cache and search advertising as different types of information completed.    Jxta reference to the realization of a Java interpreter and to make releases - cache - Search (publish-cache-search) process is simple centralized service layer. 

  Jxta in the group, such as the role of a regional network (network-partitioning) mechanism to ensure that advertising has only been able to relay to the use of these advertising group members.    Such as the different groups can be included on an equal and reciprocal group of different combinations of services, as a function of the bundle beam mechanism.    Peer Group can also play a specific application domain of the role of certification. 

  Mdidgen Utility 

  Practical category com.ibm.jxta.mdidgen decentralized approach can be used to generate targets for the reunification of Jxta address.    It generates a new ModuleClassID, a corresponding ModuleSpecID and one with a group (at the time of reading was specified in the configuration file) linked to the new PipeID.    These generated by ID immediately Java can be used in the statement form, and can be immediately inserted into your code.    That's why we ModuleSpecAdvertisement and centralized services for pipeline generation ID approach. 

  Jxta Jxta design services and client let us return to the example of weather.    From the concept that the focus must be achieved for: 

  Read and deal with the appropriate configuration file for accession to tell on which Jxta group.    (Sample code included in the package we have examples of configuration files.) 

  Start Jxta. 

  Added to the configuration file specified by the group. 

  Conducted a search to determine the focus of the service advertising the existence; If it does not exist, and on the creation of a release it. 

  Create a service corresponding to the input channels. 

  In the pipeline waiting for the news from the traps. 

  Once the news arrived, on the handling and storage to it in the RDBMS. 

  Back to Step 6. 
  Com.ibm.jxta.Concentrator logic in this category to achieve.    You can download from the reference part of this category and from all this code. 

  Collector must be achieved: 

  Read and deal with the above configuration files. 

  Start Jxta. 

  Added to the configuration file specified by the group. 

  Found on the service for advertising; If the service advertisements should not be used, we will be unable to continue. 

  Pipeline collected from the advertising information services. 

  From time to time to collect data. 

  Includes the creation of location and data collection information. 

  Through the pipeline will be sent to the concentration of news services. 

  Back to Step 6. 
  Com.ibm.jxta.Collector logic in the above categories to achieve. 

  Decomposition of the public mandate to DwJxtaPeer super-category has many tasks and concentrate on the collection of the role of the public are.    In order to eliminate unnecessary duplication of code and future maintenance much simpler for us to break down these public mandate com.ibm.jxta.DWJxtaPeer Add super-called category. 

  One ModuleSpecAdvertisement public mandate to implement the discovery (see notes JXTA in the service advertisements about this advertising more knowledge).    This from a list of findModuleSpecAdv () method implementation: 

  List 1. FindModuleSpecAdv () 
  Protected ModuleSpecAdvertisement findModuleSpecAdv () ( 
  Return (ModuleSpecAdvertisement) findAdv ( "ModuleSpecAdvertisement" 
  "Name," ModuleSpecName, new ModuleSpecAdvValidator (), false); 
  ) 

  Please note that findModuleSpecAdv () call another called findAdv () and common methods, we have found that this method of advertising.    FindAdv () parameters are: 

  Parameter Description 
  AdvType types of advertising string description - for example, PipeAdvertisement. 
  Attr search ads to match the mark - for example, Name. 
  Value to the specific attributes match. 
  Validator FindValidate an interface to achieve the target.    This interface is a way checkAdv (), to find when an advertisement, this method is used to immediate verification of this advertising. 
  LocalOnly a Boolean signs that the discovery should only be in the implementation of local, or across the network in the remote execution. 

  2 as shown in the list, the method through the use of the first part of the group that services getLocalAdvertisement () method, solely on the basis of local advertising cache found that the implementation of the advertisements.    Please note that the validator.checkAdv () call, to find any of the advertisements to verify. 

  List 2. FindAdv (), Part 1 
  Protected Advertisement findAdv (String advType, String attr, String val, 
  FindValidate validator, boolean localOnly) ( 
  Enumeration enum = null; 
  System.out.println ( "Looking for" advType + + ", please wait …"); 
  / / First look in the local storage 
  Try ( 
  Enum = discovery.getLocalAdvertisements (DiscoveryService.ADV, 
  Attr, val); 

  ) Catch (Exception e) ( 
  ) 

  If ((enum! = Null) & & (enum.hasMoreElements ())) ( 
  Advertisement adv = null; 
  While (enum.hasMoreElements ()) ( 
  Try ( 
  Adv = (Advertisement) enum.nextElement (); 
  If (validator.checkAdv (adv)) 
  Return adv; 
  ) Catch (Exception e) ( 
  Continue; 
  ) 
  ) / / While 
  ) / / If 

  If the discovery is a local, in the logic here stop.    Otherwise, we will send an enquiry to the network, remote found.    Found that the service will find any advertisements are stored in the local cache.    As long as we are given time can be found to have taken place so remote.    3 in the inventory cycle lasted about five seconds: 

  List 3. FindAdv (), Part 2 
  If (localOnly) 
  Return null; 

  System.out.println ( "cannot find it locally, trying remote"); 
  / / Now, the search remote 
  Discovery.getRemoteAdvertisements (null, DiscoveryService.ADV, 
  Attr, val, 2, null); 

  / / Wait a bit in order to get an answer. 
  Int i = 0; 
  While (true) ( 
  Try ( 
  If (i> MAXRETRIES) ( 
  System.out.print ("."); 
  Break; 
  ) 
  Thread.sleep (WaitingTime); 
  I + +; 
  ) Catch (Exception e) ( 
  ) 
  System.out.println (""); 

  At this time, has been found in any advertisements should be able to find in the local cache.    4 in the list, we are once again the implementation of a local inspection. 

  List 4. Findadv (), Part 3 
  / / Look in the local storage again 
  Try ( 
  Enum = discovery.getLocalAdvertisements (DiscoveryService.ADV, 
  Attr, val); 

  If ((enum! = Null) & & (enum.hasMoreElements ())) ( 
  Advertisement adv = null; 

  While (enum.hasMoreElements ()) ( 
  Try ( 
  Adv = (Advertisement) enum.nextElement (); 
  If (validator.checkAdv (adv)) 
  Return adv; 
  ) Catch (Exception e) ( 
  Continue; 
  ) 
  ) / / While 
  ) 
  ) Catch (Exception e) ( 
  ) 
  ) 
  Return null; 
  ) 

  Super-class public in the other two methods described in the following table; You can practice as a complete their analysis. 

  Description 
  PublishModuleSpecAdv () If it is found that the process did not find the existing ModuleSpecAdvertsiement services, the focus of this method is called.    This method will create a service (according to our generation, fixed service ID).    This advertisement will be published in the local and remote.    Only concentrate for the first time in the launch, when the configuration changes, or in the local cache was removed, can create the necessary advertising. 
  JoinGroupIfExists () for the collection of this approach and focus of the call; it has been trying to join a sub-group named (subgroup), the sub-group is an overall NetPeerGroup (default circumstances everyone in the group) of (child) group. 

  See a list of five, it is kind of constant DwJxtaPeer part of the part of the statement: 

  5 list. Module ID definition 
  Public static final String ClassID = 
  "Urn: jxta: uuid-EE99266A1DE84E3DB34D9CC842EC889105"; 
  Public static final String SpecID = 
  "Urn: jxta: uuid-EE99266A1DE84E3DB34D9CC842EC8891B9EB13ECA6FE44DDA112B5F5E357763006"; 

  Jxta in service advertisements 

  Advertising concept of decomposition into a group of inter-related advertising (a total of 103): 
ModuleClassAdvertiseent
ModuleSpecAdvertisement
MdouleImplAdvertisement

  In order to reduce the cycle of the system in the size of advertising, as well as to the general category of services (for example: banks), such specific regulations (for example: deposits and withdrawals API) and the services (such as: Java API based on the realization ) the realization of the relationship between standardized, it is necessary. 

  Jxta applications or services without the use of all such advertising, as long as it needs to use up.    In our system, we need only ModuleSpecAdvertisement, we will use the services connected to the pipeline, and this ad is the distance can be found. 

  ModuleClassID and ModuleSpecID with mdidgen utility generates and put in hard coding module; them with a centralized service for the corresponding ID.    All know the focus of the ID, and the ID has been generated if unchanged, the collection group for sure be able to find the focus of services.    ModuleSpecID because of the need ModuleClassID generation, so there are ModuleClassID.    In order to easily generate these ID, we use a library called AdvCooker, it is WR Bauer (vasha@jxta.org) created by the wire-called jxta Jxta part of the project. 

  Operation of all network concentrators with a focus on examples of the group, and other services (by using the same radio channel ModuleSpecID interception and the same logic examples) to respond.    This will ensure that the redundancy to achieve concentrated in the service of such groups always available. 

  Focus: a group of services such as on Jxta we look at com.ibm.jxta.Concentrator achieve.    We have already mentioned, it is a continuation (Extension) since DwJxtaPeer category.    Here is one by one method to the description of the Concentrator: 

  Description 
  Init () it should be called by such a method.    This method calls private jxtaInit () method, and then input on the creation of an example of pipeline services. 
  Process () method to enter this an infinite loop.    In the importation of services focused on the interception of imported pipeline for the collection of data submitted.    For each submission, it has called processData () for data processing. 
  FindPipeAdv () This method of advertising for local services pipeline found (ie, it checks the local cache). 
  JxtaInit () method first read this configuration file and configuration we want to join the group.    Then, it started Jxta and NetPeerGroup network, and then call the super class joinGroupIfExist () by adding to the designated group.    Then, if we can, it retrieved from the local cache pipeline service advertisements; Otherwise, it will create a new channel of advertising services (through the use of createInputPipeAdvIfNotExist ()).    Finally, it found that the implementation, see if it can be found ModuleSpecAdvertisement; If you can not find, and it creates a release it. 
  ProcessData () This method is placeholders.    In the actual project, which will use back-end client / server network will be collected by the data submitted to the RDBMS (may use JDBC). 
  CreateInputPipeAdvIfNotExist () method, the assistant checks the cache to see whether advertising pipeline services available.    If not used, it will create the advertising and saves it to the cache.    In the case have the right to return to advertising. 

  Static types are defined as follows: 

  Public static String servicePipeID = 
  "Urn: jxta: uuid-969610EE8945417CA56F9771197EE3965207E4C303154E7EB5878751AE22761804"; 

  This is generated by the utility mdidgen pipeline ID.    It is the unity of the service pipeline addresses for use by all concentrated.    It is a broadcast channel, thereby interception of information on all those who should receive from the collection of news.    ModuleSpecAdvertisement collectors from as part of the pipeline was in the pipeline advertising ID; collectors through the discovery process to find the advertisement. 

  Collection: preparation of client logic Jxta code Finally, we look at the category of local com.ibm.jxta.Collector methods. 

  Description 
  Init () It should be called from this category of the first method.    This method calls private jxtaInit (), and then will be used to create the data collected sent to the centralized services for the transmission pipelines. 
  Process () This method is an infinite loop, this cycle First Call collectData () access to the data measured, and then to create a centralized Jxta along with information and services it will be sent to the pipeline are waiting for the concentrator.    Sampling each cycle within a fixed period of time are delayed. 
  JxtaInit () method first read this configuration file and we want to join the group set, and then determine the location of traps.    Then, it started Jxta and NetPeerGroup network, and then call the super class joinGroupIfExist () by adding to the designated group.    Then, it found that the implementation, see if it can be found corresponding to the well-known concentration of services ModuleSpecAdvertisement If not, the denunciation.    ModuleSpecAdvertisment Once found, it will be taken on for pipeline services for the advertising and the creation of export pipelines to prepare. 
  CollectData () This method is a placeholder for the actual data collection.    In the actual project, this approach will visit various data input channel (may use input / output ports or the machine code) and the data collected by the return to the caller. 

  Actual operating Jxta: In your own machine test the dynamic network with the source code of this package, there is a test for you to the directory structure.    Below the subdirectory under the directory in the code: 

  Table of Contents Description 
  Jxta lib from the core all the latest stable version of the jar file, for Jxta shell, as well as all the jar files from jxta-wire project jxta-wire.jar documents are here.    (Please refer to reference information on Jxta shell and jxta-wire for more information.) 
  Src contains the source code for our system. 
  Our system includes classes compiled class files. 
  Shell1 first experiment directory.    We will be in the directory with a focus on the creation of a shell for.    We will fully examine here mdidgen utility. 
  Shell2 set to the network, such as on the second machine.    This will be another focus for running. 
  Shell3 set in the network, such as machine on the third.    This will run a collector. 

  To compile the code, you need to install the JDK 1.3 or later.    In the code directory, the Executive MAKEIT.BAT batch file.    This will be compiled code and create a directory of classes in the class files. 

  Then, running MAKEJAR.BAT batch file.    This will create a code dwjxta.jar contain all documents it will be put lib directory, prepared for the experiment. 

  Now, activate three different command window.    They were the directory will be changed to shell1, shell2 and shell3. 

  In shell1 runshell.bat edit documents in the directory will be used during your configuration settings in the security of user IDs and passwords reflected (password must be at least eight characters long).    Mdidgen.bat runconc.bat and edit documents, the same should have user IDs and passwords. 

  Use runshell.bat run this shell, as shown by the following configuration of this machine, such as: 

  On the machine, such as: node1 
  Transmission: TCP / IP open HTTP disabled, selected as a focal point, no relay used by TCP ports: 9701 
  Security of user names and passwords: If the batch file in the custom 

  Because we assume that the system has been created for the operation of a group, so we need to create the shell of this group.    In the middle of the shell, use the following command to create dwtest group: 

  Jxta> = mkadv myadv-g dwtest 
  Jxta> = mkpgrp mygrp-d myadv dwtest 

  This will create we will use dwtest group.    You can confirm that it has been created: 

  Jxta> groups 
  Group0: name = dwtest 

  Now you can withdraw from the shell. 

  Now, please use the test unified address mdidgen.bat document (ID) distributed generation.    When you run this paper, this should be similar to the output: 

  List 6. Mdidgen.bat output 
  Remote group discovery message sent 
  Group joined successfully 
  Public static final String ClassID = 
  "Urn: jxta: uuid-DCDD418FCC194040AA13A52A334B967105"; 
  Public static final String SpecID = 
  "Urn: jxta: uuid-DCDD418FCC194040AA13A52A334B96716C515B975C2941AD9FBC90178B6918A806"; 
  Public static final String PipeID = 
  "Urn: jxta: uuid-2184CACA259B42E0A866AEA788A923054C519D304E07415195B0917C81238FD004"; 

  Please note generated by the ModuleClassID, ModuleSpecID and PipeID.    This is what we agreed on the use of ID services approach. 

  Runconc.bat activated through the implementation of document-focused.    This will be read dwConfig file told concentrator into dwtest group.    And the output you should be somewhat similar to this: 

  List 7.1号concentrated (runconc.bat) output 
  Starting Jxta … 
  Joining default NetPeerGroup … 
  Attempting to join group: dwtest 
  Remote group discovery message sent 
  Group joined successfully 
  Group dwtest joined successfully 
  Look for previously created Pipe Adv, create one if not exist 
  Looking for PipeAdvertisement, please wait … 
  Previously published pipe advertisement not found, and creating a new one. 
  Locally caching the new pipe advertisement … 
  Checking to see if MSA previously published … 
  Looking for ModuleSpecAdvertisement, please wait … 
  Cannot find it locally, trying remote 
  … MSA not found, the need to create it 
  Creating new MSA 
  Locally and remotely publish the MSA 
  Creating pipe for data collection … 
  Pipe created successfully 
  Waiting for data from collector … 

  Here, and concentrate on the establishment of good examples, and to receive from the data collection has been well prepared for. 

  Now, in the command window to shell2 runconc.bat edit documents, the security of your user IDs and passwords reflected.    Then, running on the use of runconc.bat document for example.    In the allocation process to set the following parameters: 

  On the machine, such as: node2 
  Transmission: TCP / IP open HTTP banned, no focal point, no relay used by TCP ports: 9702 
  Security of user names and passwords: If the batch file in the custom 

  If everything is running properly, you should see output similar to this: 

  List 8.2号focus (from the Shell2 runconc.bat output) 
  Starting Jxta … 
  Joining default NetPeerGroup … 
  Attempting to join group: dwtest 
  Remote group discovery message sent 
  Group joined successfully 
  Group dwtest joined successfully 
  Look for previously created Pipe Adv, create one if not exist 
  Looking for PipeAdvertisement, please wait … 
  Checking to see if MSA previously published … 
  Looking for ModuleSpecAdvertisement, please wait … 
  .. Found previously published MSA 
  Creating pipe for data collection … 
  Pipe created successfully 
  Waiting for data from collector … 

  Please note that the focus of the ModuleSpecAdvertisement be found, so the focus-not another example of the creation of a ModuleSpecAdvertisement.    Now it is waiting for input from the traps. 

  Finally, the window in order to shell3 runcoll.bat edit documents, the security of your user IDs and passwords reflected.    Then, the use of traps running runcoll.bat document examples.    This example will use the dwColConfig shell3 directory paper told traps should be added to dwtest group, the group position is "Timbuktu North."    In the allocation process to set the following parameters: 

  On the machine, such as: node3 
  Transmission: TCP / IP open HTTP banned, no focal point, no relay used by TCP ports: 9703 
  Security of user names and passwords: If the batch file in the custom 

  Examples of this collection will begin View ModuleSpecAdvertisement and should be able to find.    Then, it will create a channel and the focus has been running for communication.    You should see output similar to this: 

  List 9. Collection (from the runcoll.bat Shell3 output) 
  Reading config file, dwColConfig, and processing … 
  Group to join will be dwtest 
  Collector location is Timbuktu North 
  Starting Jxta … 
  Joining default NetPeerGroup … 
  Attempting to join group: dwtest 
  Remote group discovery message sent 
  Group joined successfully 
  Group dwtest joined successfully 
  Searching for collector's MSA … 
  Looking for ModuleSpecAdvertisement, please wait … 
  Cannot find it locally, trying remote 
  .. Found collector's MSA 
  Extracting pipe adv from MSA … 
  Connecting to concentrator network … 
  Pipe created successfully 
  … Collecting data …. 
  … Data collected, sending to concentrator 
  Waiting until next sample … 
  … Collecting data …. 
  … Data collected, sending to concentrator 
  Waiting until next sample … 

  Please note that the data is collected and regularly sent to the concentration of services.    When the data through the P2P network, as well as for receiving these two centralized data processing, note that observation. 

  Application of a very difficult weather pattern we collect examples of the application of such a model: In general, it's prevalent use of P2P systems from specific areas, it uses Jxta.    This model consists of two coupled extremely loose groups: consumers and producers.    When consumers want products producers, consumers are reluctant to make firm promises, do not want to subject to a specific producer.    In this kind of thinking may be behind a number of practical motives.    Consumers may think: 

  Can be selected at any time, can be used to select the best producer 

  A reduction of producers rely on the success or failure of risk 

  From the very large dynamic community of choice, and the size of this community in the physical topology is difficult to manage when the producer groups and consumer groups overlap there, this model has become very interesting, currently available, popular , the world's file-sharing system on the example of this point.    With the traditional different networking technology, P2P system designed from the beginning to adapt to this application model.    In particular, and the use of traditional client / server technology for the design, it must provide the complex solutions, Jxta makes the creation of these systems is easy and easily. 

  Beyond TCP / IP networking Jxta to really highlight the value of, I have chosen to the global meteorological information collection system as an example.    However, the problem has many solutions and business model (business scenario), the typical characteristics of these business circumstances such as mobile sales force automation, commodity trade, content distribution and business to business e-commerce, and so on, can list many.    You can also use P2P networks and the traditional client / server network, which greatly exceed today's passive construction of a new border network solutions.    Jxta open-source platform will be these new tools to achieve solutions.    I hope this series has aroused Jxta you explore the possibilities offered aspirations. 

  Ibm developer from - 
  Java, java, J2SE, j2se, J2EE, j2ee, J2ME, j2me, ejb, ejb3, JBOSS, jboss, spring, hibernate, jdo, struts, webwork, ajax, AJAX, mysql, MySQL, Oracle, Weblogic, Websphere, scjp, scjd 
  ↑ Back 

Will Database Programming how to do unit testing? Network Programming how to do unit testing?

  Abstract: I would like to ask, Database Programming how to do unit testing? Network Programming how to do unit testing? 


  Such as that recently conducted a study to test units encountered these two issues. Out how not to want to. Special to you ask for advice, thank you. 



  Passing Bangniding 



  God?? 



  Bangniding 



  Database Programming aspects available, isolation tiered testing can be used mock, 
  Network programming can also use mock, such as springmock, can be simulated httprequest, 



  Now so many techniques and methods, which one is your own thought out? - And the people have come up with what they did not learn and practice on a vacuum can come up with?? 

  Give you two words: learning. 



  I wonder if people upstairs to Yuesha ….. can think of to say, really do not desire 

  In fact, there are many NEE unit testing can be used, focusing on all the different focus on network programming is relatively good HTTPUNIT (http://httpunit.sourceforge.net) 
  HTMLUnit (http://htmlunit.sourceforge.net/) 

  JMeter test database performance, I do not know is not the main floor, 

  Strongly recommend automatic generation of JTest unit testing, the proposed landlord look 




  Thank you upstairs response. Out of a recent book called  .
  Http://www.china-pub.com/computers/common/info.asp?id=30898 

  I need to look at the. Huh. 




  ↑ Back 

Socket to use Java Network Programming (c)

  Abstract: Using a Java Socket Network Programming (c) 

  : From:天极net Xi Min at 9:28 on November 11, 2002 
  Attachment: the realization of the server code 

  Import java.net .*; 
  Import java.io. *; 
  Import java.awt.event.ActionEvent; 
  Import java.awt.event.ActionListener; 

  Public class talkServer 
  (Public static void main (String [] args) 
  Try ( 
  (File: / / server set up ServerSocket server = new ServerSocket (9998); 
  Int i = 1; 
  For (;;) 
  Socket incoming = (server.accept (); 
  New ServerThread (incoming, i). Start (); 
  I + +; 
  ) 
  ) Catch (IOException ex) ( 
  Ex.printStackTrace (); 
  ) 
  ) 
  ) 

  Class ServerThread extends Thread implements ActionListener 
  ( 
  Private int threadNum; 
  Private Socket socket; 
  TalkServerFrm t; 
  BufferedReader in; 
  PrintWriter out; 
  Private boolean talking = true; 
  Public ServerThread (Socket s, int c) 
  (ThreadNum = c; 
  S = socket; 
  ) 

  Public void actionPerformed (ActionEvent e) 
  (Object source = e.getSource (); 
  Try ( 
  If (source == t.btnSend) 
  (Out.println (t.getTalk ()); 
  T.clearTalk (); 
  ) Else 
  If (source == t.btnEnd) 
  (Out.println ( "'s termination process is the other side"); 
  Out.close (); 
  In.close (); 
  Talking = false; 
  ) 
  ) Catch (IOException ex) ( 
  ) 
  ) 

  Public void run () 
  (Try ( 
  T = new talkServerFrm (new Integer (threadNum). ToString (), this); 
  T.setSize (500,500); 
  T.show (); 
  In = new BufferedReader (new 
  InputStreamReader (socket.getInputStream ())); 
  Out = new PrintWriter (socket.getOutputStream (), true); 
  ) Catch (Exception e) ( 
  ) 
  New Thread () 
  (Public void run () 
  (Try ( 
  While (true) 
  (CheckInput (); 
  Sleep (1000); 
  ) 
  ) Catch (InterruptedException ex) ( 
  ) Catch (IOException ex) ( 
  ) 
  ) 
  ). Start (); 
  While (talking) 
  () 
  T.dispose (); 
  ) 

  Private void checkInput () throws IOException 
  (String line; 
  If ((in.readLine ())!= line = null) 
  T.setPartner (line); file: / / This is the method in the interface type, 
  File: / / line will be used to output the contents of the user interface) 
  ) 

  Java, java, J2SE, j2se, J2EE, j2ee, J2ME, j2me, ejb, ejb3, JBOSS, jboss, spring, hibernate, jdo, struts, webwork, ajax, AJAX, mysql, MySQL, Oracle, Weblogic, Websphere, scjp, scjd 
  ↑ Back 

UDP data based on the local area network broadcasting the proceedings _1

  Abstract: Based on a UDP LAN data broadcasting the proceedings _1 

  Testing procedures on the design process conclusions About the author 

  JIANG Qing Ye (qjiang@ieee.org) 
  Navigation and control of the United States company 
  November 2001 

  This paper introduces the general network communication in the transmission control protocol (TCP) and user data packet protocol (UDP), and use of the Java language designed a simple UDP based on the local area network data broadcasting the proceedings, and has demonstrated in the Java language for UDP send and receive data the general steps.    The Java language features excellent cross-platform, the system can run without modification of the Windows, Linux, Mac OS, such as a series of different platforms. 
  Introduction With the popularity of network technology, network meetings in the companies, enterprises and units of more widely.    A network conferencing system usually includes a server and a client program.    Which is responsible for the server-side user management, information and interactive voting statistics; listen to the client to achieve the statement, public statements, private discussion, a vote and so on.    In a Web Conference System Design and Implementation, usually related to the graphical user interface design, TCP / IP connections, UDP data broadcasting, such as a series of multi-threading technology.    In this paper, a simple example program, and has demonstrated in the Java language for sending and receiving data UDP general steps and UDP data broadcasting in the local area network system in the role. 

  TCP (Transmission Control Protocol, Transmission Control Protocol) is a communication protocol based on connections.    When the two computers need for reliable data transmission, they build a stable network connections, such connections are usually referred to as data links.    And the telephone network is similar to this is point-to-point data links, communication between the parties through this data links transmit data back and forth.    In this chain of stability data on the basis of information through the TCP protocol verification to ensure that the recipient received the data and sent by the sender in the content and sequence data is completely consistent in order to achieve reliable data transmission . 

  UDP (User Datagram Protocol, User Datagram Protocol packets) and the difference between the TCP protocol is based on UDP is not a stable connection protocol.    UDP protocol will be independent of the data packet transmission from one computer to another computer, but does not guarantee that the recipient can receive the packet or that the recipient received the data and sent by the sender and the contents and data the order is completely consistent.    Therefore, UDP protocol similar to the more general postal service, the sender can not guarantee that the letter sent to the addressee can be received in a timely manner, the letter may be issued after the first issue than the earlier letter arrived. 

  For many applications, in communications between two computers to ensure a reliable and stable data links is crucial.    In such circumstances, we should first consider the use of the TCP protocol in the computer Liangsi established between TCP / IP connection.    In HTTP (Hyper-Text Transfer Protocol, hypertext transfer protocol), FTP (File Transfer Protocol, File Transfer Protocol), and TELNET application, called in communications between the two sides built up a stable of reliable data links, and therefore they are TCP protocol used for data transfer. 

  In the TCP protocol, the sender and receiver must be exchanged for additional information to ensure that the recipient has received the data packets sent and received by the data and sent by the sender in the content and sequence data are completely consistent.    These additional exchange of information improved the reliability of data transmission, but also to the network brought an extra burden, leading to the delayed data exchange, thereby reducing overall network data exchange capacity.    For some of the real-time applications that require a higher, such delays may be unacceptable.    For example, a millisecond clock frequency according to a certain server to the client at the time to provide data, if these time data transmission in the course of being a larger delay, the time these outdated data is totally meaningless, even if the client accuracy of the data received.    On the contrary, if received by the clients of every data packet is a real-time, then even if the client missed 12 packet is acceptable, because he was always behind can receive data packets on their own corrected.    Therefore, the real-time requirements of the relatively high but relatively low transmission reliability requirements of the application procedures, the UDP protocol is clearly an appropriate choice. 

  In common Ethernet (Ehternet) architecture, the computers in a computer data exchange between the switch through to completion.    If the data needs transmitted to a receiver more than in the use of TCP / IP connectivity circumstances, the need to send data to the switch sent the same copy of N, N switches are responsible for these copies distributed to all the receivers ; in the use of UDP data broadcasting circumstances, the data are sent only to send a copy switches, switches, will be responsible for the production of N copies of the information sent to all machines.    In such cases, the use of TCP / IP connectivity will greatly increase the burden on the network.    In an ordinary local area network, the network can be considered because of poor conditions and the possibility of data loss caused relatively small, and data broadcasting using UDP data exchange, can substantially reduce the burden of network, the design of a data broadcasting based on UDP LAN Conference System completely feasible. 

  Normally, a computer only a physical interface can connect to a network, all the applications have passed the physical interface to receive data from the network or sending data to the network.    As a network at the same time there are multiple computers, and a computer at the same time there may need multiple applications and network data exchange, we normally use IP and port number to identify the need for exchange of data and computer applications.    Each computer by a 32 to identify the IP addresses in a network, the IP address of each computer is the only and therefore applications according to IP address to send data to the correct computer.    Each needs and network data exchange system applications are assigned a 16-bit port, the system will be under the port of the network to receive data transmitted to the corresponding applications.    The scope of the port from 0 to 65,535, from 0 to 1023 was retained by the system is mainly used to provide HTTP, FTP and TELNET, and other system services, the user's own applications should not attempt to use less than 1023 to the end mouth. 

  Java language is a significant advantage of the high degree of it from the language has provided support for the network, making the programmers can easily build Web-based applications.    In the Java 1.3 version of the standard class library java.net provides five Java interface, as well as 21 categories in these interfaces and on the basis of class, programmers can easily achieve almost all of the common network application.    For example, can be used to construct ServerSocket based on TCP / IP server that can be used to build Socket based on TCP / IP clients, and DatagramSocket DatagramPacket and UDP can be used to build based on the data broadcasting procedures.    Java.net in the other Java can be used to achieve the domain name parsing, authentication, security clearance and a series of functions.    As a result of these Java library functions and the specific use and the content goes beyond the scope of the discussion in this paper, and interested readers can further reference documents, as well as Java, Sun's Java Tutorial information. 

  This simple process involves the following three modules: 

  Data Broadcasting and receiver modules - Broadcast.java 
  Data reception thread - Receiver.java 
  Graphical user interface - Chat.java 

  Design data broadcasting and receiving modules Broadcast.java this example is the core of the process.    These include a construction method, a method of sending data and a data reception methods.    In order to enable this type can be more widely applied to other applications, the authors also added a port configuration method. 

  In the construction method, we first use InetAddress definition of a data broadcasting group, at the same time construct a DatagramSocket used to send data and receive data for a MulticastSocket.    Here we use 230.0.0.1 as data broadcasting group identifiers, although this marked with the IP address at the same format, but it does not mean that on the Internet a machine.    In addition, we in the port configuration methods are designated 1235 ports and 1236 port-bit data port to send and receive data.    If a UDP data broadcasting system likened radio system, data broadcasting identifiers can be considered a band, and data reception port can be considered is the frequency.    Radio users must be adjusted to the radios and the corresponding frequency band to be able to receive radio signals, the UDP data reception procedures must also be added corresponding to the data broadcasting group and use the correct data ports can receive the right to receive broadcast data UDP .    In the construction method, we use the constructor function MulticastSocket designated ports to receive data (frequency), and use its joinGroup method specified data broadcasting group (band). 

  Public Broadcast () 
  ( 
  GetBroadcastPorts (); 
  Try 
  ( 
  / / Construction Data Broadcasting Group identifiers (Band) 
  BroadcastGroup = InetAddress.getByName ( "230.0.0.1"); 
  / / Send data structure port 
  Sender = new DatagramSocket (ServerPort); 
  / / Receive ports structural data (frequency) 
  Receiver = new MulticastSocket (ClientPort); 
  / / Designated to receive data ports Data Broadcasting Group (Band) 
  Receiver.joinGroup (BroadcastGroup); 
  ) Catch (Exception e) () 
  ) 

  Methods of data sent, we Based on the data provided by the users and data broadcasting target port (frequency) construct a DatagramPacket data packets, and then sent the data DatagramSocket use the method to send data packets sent to the LAN.    On the contrary, the data reception method, we first construct a DatagramPacket empty data packets, and then receive data MulticastSocket use the method receive the data packets filled with the contents.    In order to avoid data packets of different sizes of data loss caused by such troubles, we will be two special data packet set to the size of the same. 

  / / Data distribution method 
  Public void SendData (String Msg) 
  ( 
  Byte [] b = new byte [1024]; 
  DatagramPacket packet; 
  Try 
  ( 
  / / Byte sequence b include the need to send data 
  B = Msg.getBytes (); 
  / / Construction of a data packet, BroadcastGroup data broadcasting group identifiers (band), 
  / / ClientPort data broadcasting objectives port (frequency). 
  Packet = new DatagramPacket (b, b.length, BroadcastGroup, ClientPort); 
  / / Send data packets 
  Sender.send (packet); 
  ) Catch (Exception e) () 
  ) 

  / / Data reception method 
  Public String ReceiveData () 
  ( 
  Byte [] b = new byte [1024]; 
  / / Construction of an empty data packets 
  DatagramPacket packet = new DatagramPacket (b, 1024); 
  String InMsg; 
  Try 
  ( 
  / / Receive data 
  Receiver.receive (packet); 
  ) Catch (IOException e) () 
  / / Cong were receiving data packets in the data 
  B = packet.getData (); 
  InMsg = new String (b); 
  Return InMsg; 
  ) 
  Java, java, J2SE, j2se, J2EE, j2ee, J2ME, j2me, ejb, ejb3, JBOSS, jboss, spring, hibernate, jdo, struts, webwork, ajax, AJAX, mysql, MySQL, Oracle, Weblogic, Websphere, scjp, scjd 
  ↑ Back 

Socket to use Java Network Programming (b)

  Abstract: Using a Java Socket Network Programming (b) 

  : From:天极net Xi Min at 9:28 on November 11, 2002 
  Second, the establishment of the client code 

  Compared server, the client should simply, the client should use the host server and server machines ip port as a parameter to create a Socket object.    By this object, you can use the "build server" on the part of the method of data input and output. 

  Socket socket = new Socket ( "168.160.12.42," 9998); 
  In = new BufferedReader (new InputStreamReader (socket.getInputStream ())); 
  Out = new PrintWriter (socket.getOutputStream (), true); 

  Over the establishment of a code Socket object, and this object is connected to the ip address 168.160.12.42 host, the server port for the 9998 target.    And the establishment of the input and output streams flow, the output corresponding server and client write. 

  Third, the establishment of user interface 

  Readers according to their own preferences can be set up their own user interface, this is not the focus of this paper. 

  After more than three steps, we can establish a relatively simple process of dialogue.    However, in order to make this process more perfect, the following should be carried out to improve: 

  First, the server can now service a customer, which is single-threaded.    It can be improved for multi-threaded server. 

  Try 
  (File: / / server set up ServerSocket server = new ServerSocket (9998); 
  Int i = 1; 
  For (;;) 
  ( 
  Socket incoming = server.accept (); 
  New ServerThread (incoming, i). Start (); 
  I + +; 
  ) 
  ) Catch (IOException ex) (ex.printStackTrace ();) 

  Whether there is a cycle of customers connected to the server and, if so, will create a thread to service the customer, the name of this thread is ServerThread which, in turn, extends the Thread class, and its preparation method and the aforementioned servers the same way. 

  Second, in order to get the other side can always send back information in the server and client establish an independent thread to inspect the input flow, if the input stream is input, it can be immediately displayed.    Code as follows: 

  New Thread () 
  ( 
  Public void run () 
  ( 
  Try 
  ( 
  While (true) 
  ( 
  CheckInput (); 
  Sleep (1000) / / ms per 1000 of a) 
  ) Catch (InterruptedException ex) 
  ( 
  ) Catch (IOException ex) 
  ( 
  ) 
  ) 
  ). Start (); 

  The checkInput () method 
  Private void checkInput () throws IOException 
  ( 
  String line; 
  If ((in.readLine ())!= line = null) file: / / input stream detect whether there is a new data t.setPartner (line); file: / / data flow will be displayed in the news 
  ) 

  Through the above improvements, procedures can be better run. 
  Java, java, J2SE, j2se, J2EE, j2ee, J2ME, j2me, ejb, ejb3, JBOSS, jboss, spring, hibernate, jdo, struts, webwork, ajax, AJAX, mysql, MySQL, Oracle, Weblogic, Websphere, scjp, scjd 
  ↑ Back 

Establish Java network management applications (2)

  Abstract: Java development environment so that you can SolsticeTMEnterprise Manager for the creation and deployment of Java applications, these applications can be used as an independent application to run, it is also possible to run Java and fully support JDK1.1 Web browser to remotely execute.    To help the development of management applications, Solstice Enterprise Manager3.0 bundled with the three Java API…… 

  B> SolsticeEnterprise Manager for the design of application 

  Java development environment so that you can SolsticeTMEnterprise Manager for the creation and deployment of Java applications, these applications can be used as an independent application to run, it is also possible to run Java and fully support JDK1.1 Web browser to remotely execute.    To help the development of management applications, Solstice Enterprise Manager3.0 bundled with the Java API three: general management API (Generic Management API), topology API (Topology API) and Java warning API (Java Alarm API). 

  These API so that you can prepare with SolsticeEnterprise Manager3.0 communications Java applications, their functions and their SolsticeEnterprise Manager3.0 C + + similar to the procedures, the main difference only in Java API is designed to adapt to thin - client / fat server model.    In addition, the API has the following characteristics: 

  ?    Multithreading security; 
  ?    Have long-range capability, and thus can adapt to the thin-client/fat server model; 
  ?    Can be Java applets and Java applications used; 
  ?    Protocol independent.    This way, no matter what internal use agreement, the API is the same. 

  To be successfully prepared by the Java application to manage your network, you need to know Java application design principles and Java Java network management application architecture. 

  1.    Design Principles 

  Solstice Enterprise Manager Java API design process followed the following principles.    When the efficient development of Java applications and applets, it would be preferable to use these principles: 

  1) Thin category 2) of the local Remote Method 3) awarded loading data 

  2.    Application Architecture 

  The chart of a typical demonstration of the use of JMI's Java application architecture.    API can be used to create a variety of the JMA / MIS connections, or for operation and management information.    Initially, a connection request was sent to a JMA parent process, once authenticated, in the management of application / applets and on the connection between the JMA created. 



  ↑ Back 

keep looking »