Advertisement
icebit

java klient

Jun 15th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.31 KB | None | 0 0
  1.  
  2. package example;
  3.  
  4. import java.net.MalformedURLException;
  5. import java.net.URL;
  6. import java.util.logging.Logger;
  7. import javax.xml.namespace.QName;
  8. import javax.xml.ws.WebEndpoint;
  9. import javax.xml.ws.WebServiceClient;
  10. import javax.xml.ws.WebServiceFeature;
  11. import java.io.*;
  12. import java.net.*;
  13. import java.util.Date;
  14. import java.util.Arrays;
  15.  
  16. /**
  17. * This class was generated by the JAX-WS RI.
  18. * JAX-WS RI 2.1.6
  19. * Generated source version: 2.1
  20. *
  21. */
  22. @WebServiceClient(name = "ServiceService", targetNamespace = "http://Example/", wsdlLocation = "http://192.168.10.150/Example?wsdl")
  23. public class ServiceService
  24. extends javax.xml.ws.Service
  25. {
  26. /** TCP **/
  27. /************************************************************************************************************************************************/
  28. // zmienne predefiniowane ==========================================
  29. int port = 12345;
  30. String host = "192.168.10.147";
  31.  
  32. // zmienne niezainicjowane -----------------------------------------
  33. ServerSocket serverSocket;
  34. Socket connection = null;
  35. DataOutputStream out;
  36. DataInputStream in;
  37. String message;
  38. /** TCP **/
  39. /************************************************************************************************************************************************/
  40. private final static URL SERVICESERVICE_WSDL_LOCATION;
  41. private final static Logger logger = Logger.getLogger(example.ServiceService.class.getName());
  42.  
  43. static {
  44. URL url = null;
  45. try {
  46. URL baseUrl;
  47. baseUrl = example.ServiceService.class.getResource(".");
  48. url = new URL(baseUrl, "http://192.168.10.150/Example?wsdl");
  49. } catch (MalformedURLException e) {
  50. logger.warning("Failed to create URL for the wsdl Location: 'http://192.168.10.150/Example?wsdl', retrying as a local file");
  51. logger.warning(e.getMessage());
  52. }
  53. SERVICESERVICE_WSDL_LOCATION = url;
  54. }
  55.  
  56. public ServiceService(URL wsdlLocation, QName serviceName) {
  57. super(wsdlLocation, serviceName);
  58. }
  59.  
  60. public ServiceService() {
  61. super(SERVICESERVICE_WSDL_LOCATION, new QName("http://Example/", "ServiceService"));
  62. }
  63.  
  64. /**
  65. *
  66. * @return
  67. * returns Service
  68. */
  69. @WebEndpoint(name = "ServicePort")
  70. public example.Service getServicePort() {
  71. return super.getPort(new QName("http://Example/", "ServicePort"), Service.class);
  72. }
  73.  
  74. /**
  75. *
  76. * @param features
  77. * A list of {@link javax.xml.ws.WebServiceFeature} to configure on the proxy. Supported features not in the <code>features</code> parameter will have their default values.
  78. * @return
  79. * returns Service
  80. */
  81. @WebEndpoint(name = "ServicePort")
  82. public example.Service getServicePort(WebServiceFeature... features) {
  83. return super.getPort(new QName("http://Example/", "ServicePort"), Service.class, features);
  84. }
  85.  
  86. /** TCP **/
  87. /************************************************************************************************************************************************/
  88. // metoda obslugujaca klientow =====================================
  89. void run(){
  90. try{
  91. // tworzymy nowe gniazdo -----------------------------------
  92. serverSocket = new ServerSocket( port, 5 );
  93.  
  94. // akceptujemy polaczenie ----------------------------------
  95. connection = serverSocket.accept();
  96.  
  97. // wyswietlamy informacje o polaczeniu ---------------------
  98. System.out.println("Address: " + connection.getInetAddress() + " Port: " + connection.getPort() );
  99.  
  100. // pobieramy obiekty reprezentujace strumienie IN i OUT ----
  101. out = new DataOutputStream(connection.getOutputStream());
  102. out.flush();
  103. in = new DataInputStream(connection.getInputStream());
  104. this.getMessage();
  105.  
  106. }
  107. catch(IOException ioException){
  108. ioException.printStackTrace();
  109. }
  110. finally{
  111. // zamykamy strumienie: wejsciowy i wyjsciowy --------------
  112. try{
  113. in.close();
  114. out.close();
  115. // zamykamy gniazdo ------------------------------------
  116. serverSocket.close();
  117. }
  118. catch(IOException ioException){
  119. ioException.printStackTrace();
  120. }
  121. }
  122. }
  123.  
  124. void getMessage(){
  125. try{
  126. if(in != null){
  127. byte[] buffer = new byte[128];
  128. int read;
  129. int totalRead = 0;
  130. Service sObj = this.getServicePort();
  131.  
  132. while((read = in.read(buffer)) != -1){
  133. String msgToThird = new String (buffer, "UTF8");
  134. System.out.println(msgToThird);
  135. System.out.println("read: " + read);
  136. //System.out.println(buffer.length);
  137. System.out.println("In Client: " + sObj.getTime(msgToThird));
  138.  
  139. Arrays.fill( buffer, (byte)1 );
  140. }
  141. //System.out.println(read);
  142.  
  143. }
  144.  
  145. }catch(Exception e){
  146. System.out.println("eksepszyn");
  147. }
  148. }
  149. /** TCP **/
  150. /************************************************************************************************************************************************/
  151.  
  152.  
  153. public static void main(String args[]){
  154. ServiceService sObject = new ServiceService();
  155. //Service sObj = sObject.getServicePort();
  156. /* dodanie polaczenia TCP - SERWER */
  157. while(true) sObject.run();
  158.  
  159. /* koniec TCP - SERWER */
  160.  
  161. //System.out.println("In Client: " + sObj.getTime("say this pls"));
  162. }
  163.  
  164.  
  165. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement