2012-08-03 30 views
0

我正在使用一個tcp服務器通信器,並且使用在此website上發現的編碼。我在進口前五名進口商中遇到錯誤。它說它無法解決。我該如何獲得這些進口產品?在java tcp中輸入eneter的錯誤

import eneter.messaging.diagnostic.EneterTrace; 
import eneter.messaging.endpoints.typedmessages.*; 
import eneter.messaging.messagingsystems.messagingsystembase.*; 
import eneter.messaging.messagingsystems.tcpmessagingsystem.TcpMessagingSystemFactory; 
import eneter.net.system.EventHandler; 
import android.app.Activity; 
import android.os.Bundle; 
import android.os.Handler; 
import android.view.View; 
import android.view.View.OnClickListener; 
import android.widget.*; 

public class AndroidNetCommunicationClientActivity extends Activity { 
    // Request message type 
    // The message must have the same name as declared in the service. 
    // Also, if the message is the inner class, then it must be static. 
    public static class MyRequest { 
     public String Text; 
    } 

    // Response message type 
    // The message must have the same name as declared in the service. 
    // Also, if the message is the inner class, then it must be static. 
    public static class MyResponse { 
     public int Length; 
    } 

    // UI controls 
    private Handler myRefresh = new Handler(); 
    private EditText myMessageTextEditText; 
    private EditText myResponseEditText; 
    private Button mySendRequestBtn; 

    // Sender sending MyRequest and as a response receiving MyResponse. 
    private IDuplexTypedMessageSender<MyResponse, MyRequest> mySender; 

    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.tcp_server); 

     // Get UI widgets. 
     myMessageTextEditText = (EditText) findViewById(R.id.messageTextEditText); 
     myResponseEditText = (EditText) findViewById(R.id.messageLengthEditText); 
     mySendRequestBtn = (Button) findViewById(R.id.sendRequestBtn); 

     // Subscribe to handle the button click. 
     mySendRequestBtn.setOnClickListener(myOnSendRequestClickHandler); 

     try { 
      openConnection(); 
     } catch (Exception err) { 
      EneterTrace.error("Open connection failed.", err); 
     } 
    } 

    @Override 
    public void onDestroy() { 
     // Stop listening to response messages. 
     mySender.detachDuplexOutputChannel(); 
    } 

    private void openConnection() throws Exception { 
     // Create sender sending MyRequest and as a response receiving 
     // MyResponse 
     IDuplexTypedMessagesFactory aSenderFactory = new DuplexTypedMessagesFactory(); 
     mySender = aSenderFactory.createDuplexTypedMessageSender(
       MyResponse.class, MyRequest.class); 

     // Subscribe to receive response messages. 
     mySender.responseReceived().subscribe(myOnResponseHandler); 

     // Create TCP messaging for the communication. 
     // Note: 10.0.2.2 is a special alias to the loopback (127.0.0.1) 
     // on the development machine 
     IMessagingSystemFactory aMessaging = new TcpMessagingSystemFactory(); 
     IDuplexOutputChannel anOutputChannel = aMessaging 
       .createDuplexOutputChannel("tcp://10.0.2.2:8060/"); 

     // Attach the output channel to the sender and be able to send 
     // messages and receive responses. 
     mySender.attachDuplexOutputChannel(anOutputChannel); 
    } 

    private void onSendRequest(View v) { 
     // Create the request message. 
     MyRequest aRequestMsg = new MyRequest(); 
     aRequestMsg.Text = myMessageTextEditText.getText().toString(); 

     // Send the request message. 
     try { 
      mySender.sendRequestMessage(aRequestMsg); 
     } catch (Exception err) { 
      EneterTrace.error("Sending the message failed.", err); 
     } 
    } 

    private void onResponseReceived(Object sender, 
      final TypedResponseReceivedEventArgs<MyResponse> e) { 
     // Display the result - returned number of characters. 
     // Note: Marshal displaying to the correct UI thread. 
     myRefresh.post(new Runnable() { 
      @Override 
      public void run() { 
       myResponseEditText.setText(Integer.toString(e 
         .getResponseMessage().Length)); 
      } 
     }); 
    } 

    private EventHandler<TypedResponseReceivedEventArgs<MyResponse>> myOnResponseHandler 

    = new EventHandler<TypedResponseReceivedEventArgs<MyResponse>>() { 
     @Override 
     public void onEvent(Object sender, 
       TypedResponseReceivedEventArgs<MyResponse> e) { 
      onResponseReceived(sender, e); 
     } 
    }; 

    private OnClickListener myOnSendRequestClickHandler = new OnClickListener() { 
     public void onClick(View v) { 
      onSendRequest(v); 
     } 
    }; 
+0

Try Crt + Shift + O – 0gravity 2012-08-03 17:30:06

+0

您是簡單地複製粘貼網站上的代碼,還是下載並將代碼包含在您的項目中?頁面頂部有一個「獲取源代碼」鏈接。 如果您沒有包含您嘗試在項目中導入的名稱的源,則無法調用它們。它們不是Android SDK的一部分。 – AntoineG 2012-08-03 17:44:37

+0

山姆貝文斯如何解決這個問題,請分享 – 2015-03-14 06:52:01

回答

0

我從eneter網站下載了jar文件。這樣做後,我能夠改變我的構建路徑和日食能夠了解進口。