Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package example;
- import java.net.MalformedURLException;
- import java.net.URL;
- import java.util.logging.Logger;
- import javax.xml.namespace.QName;
- import javax.xml.ws.WebEndpoint;
- import javax.xml.ws.WebServiceClient;
- import javax.xml.ws.WebServiceFeature;
- import java.io.*;
- import java.net.*;
- import java.util.Date;
- import java.util.Arrays;
- /**
- * This class was generated by the JAX-WS RI.
- * JAX-WS RI 2.1.6
- * Generated source version: 2.1
- *
- */
- @WebServiceClient(name = "ServiceService", targetNamespace = "http://Example/", wsdlLocation = "http://192.168.10.150/Example?wsdl")
- public class ServiceService
- extends javax.xml.ws.Service
- {
- /** TCP **/
- /************************************************************************************************************************************************/
- // zmienne predefiniowane ==========================================
- int port = 12345;
- String host = "192.168.10.147";
- // zmienne niezainicjowane -----------------------------------------
- ServerSocket serverSocket;
- Socket connection = null;
- DataOutputStream out;
- DataInputStream in;
- String message;
- /** TCP **/
- /************************************************************************************************************************************************/
- private final static URL SERVICESERVICE_WSDL_LOCATION;
- private final static Logger logger = Logger.getLogger(example.ServiceService.class.getName());
- static {
- URL url = null;
- try {
- URL baseUrl;
- baseUrl = example.ServiceService.class.getResource(".");
- url = new URL(baseUrl, "http://192.168.10.150/Example?wsdl");
- } catch (MalformedURLException e) {
- logger.warning("Failed to create URL for the wsdl Location: 'http://192.168.10.150/Example?wsdl', retrying as a local file");
- logger.warning(e.getMessage());
- }
- SERVICESERVICE_WSDL_LOCATION = url;
- }
- public ServiceService(URL wsdlLocation, QName serviceName) {
- super(wsdlLocation, serviceName);
- }
- public ServiceService() {
- super(SERVICESERVICE_WSDL_LOCATION, new QName("http://Example/", "ServiceService"));
- }
- /**
- *
- * @return
- * returns Service
- */
- @WebEndpoint(name = "ServicePort")
- public example.Service getServicePort() {
- return super.getPort(new QName("http://Example/", "ServicePort"), Service.class);
- }
- /**
- *
- * @param features
- * 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.
- * @return
- * returns Service
- */
- @WebEndpoint(name = "ServicePort")
- public example.Service getServicePort(WebServiceFeature... features) {
- return super.getPort(new QName("http://Example/", "ServicePort"), Service.class, features);
- }
- /** TCP **/
- /************************************************************************************************************************************************/
- // metoda obslugujaca klientow =====================================
- void run(){
- try{
- // tworzymy nowe gniazdo -----------------------------------
- serverSocket = new ServerSocket( port, 5 );
- // akceptujemy polaczenie ----------------------------------
- connection = serverSocket.accept();
- // wyswietlamy informacje o polaczeniu ---------------------
- System.out.println("Address: " + connection.getInetAddress() + " Port: " + connection.getPort() );
- // pobieramy obiekty reprezentujace strumienie IN i OUT ----
- out = new DataOutputStream(connection.getOutputStream());
- out.flush();
- in = new DataInputStream(connection.getInputStream());
- this.getMessage();
- }
- catch(IOException ioException){
- ioException.printStackTrace();
- }
- finally{
- // zamykamy strumienie: wejsciowy i wyjsciowy --------------
- try{
- in.close();
- out.close();
- // zamykamy gniazdo ------------------------------------
- serverSocket.close();
- }
- catch(IOException ioException){
- ioException.printStackTrace();
- }
- }
- }
- void getMessage(){
- try{
- if(in != null){
- byte[] buffer = new byte[128];
- int read;
- int totalRead = 0;
- Service sObj = this.getServicePort();
- while((read = in.read(buffer)) != -1){
- String msgToThird = new String (buffer, "UTF8");
- System.out.println(msgToThird);
- System.out.println("read: " + read);
- //System.out.println(buffer.length);
- System.out.println("In Client: " + sObj.getTime(msgToThird));
- Arrays.fill( buffer, (byte)1 );
- }
- //System.out.println(read);
- }
- }catch(Exception e){
- System.out.println("eksepszyn");
- }
- }
- /** TCP **/
- /************************************************************************************************************************************************/
- public static void main(String args[]){
- ServiceService sObject = new ServiceService();
- //Service sObj = sObject.getServicePort();
- /* dodanie polaczenia TCP - SERWER */
- while(true) sObject.run();
- /* koniec TCP - SERWER */
- //System.out.println("In Client: " + sObj.getTime("say this pls"));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement