2011-11-28 19 views
0

新手在這裏。我成功地創建了一個使用c#的聊天服務器(服務器部分代碼在下面,雖然有權利去所有者),客戶端能夠連接並且按照預期工作。現在我的問題是我可以做一個客戶端應用程序,將從Android連接?是否有可能使C#聊天服務器與Android客戶端使用套接字

private void loadchatserver() 
    { 
     try 
     { 
      // Initialise the ArrayList of connected clients 
      this.clientList = new ArrayList(); 

      // Initialise the delegate which updates the status 
      this.updateStatusDelegate = new UpdateStatusDelegate(this.UpdateStatus); 

      // Initialise the socket 
      serverSocket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); 

      // Initialise the IPEndPoint for the server and listen on port 30000 
      IPEndPoint server = new IPEndPoint(IPAddress.Any, pubcommandport); 

      // Associate the socket with this IP address and port 
      serverSocket.Bind(server); 

      // Initialise the IPEndPoint for the clients 
      IPEndPoint clients = new IPEndPoint(IPAddress.Any, 0); 

      // Initialise the EndPoint for the clients 
      EndPoint epSender = (EndPoint)clients; 

      // Start listening for incoming data 
      serverSocket.BeginReceiveFrom(this.serverdataStream, 0, this.serverdataStream.Length, SocketFlags.None, ref epSender, new AsyncCallback(ReceiveServerData), epSender); 

     } 
     catch (Exception ex) 
     { 
       MessageBox.Show("Loadchatserver: " + ex.Message); 
     } 
    } 

回答

2

當然可以。
套接字是任何主流編程語言都支持的全局協議。

下面是套接字在Java中一個很好的教程(應與工作的Dalvik以同樣的方式 - 在Android的Java實現): http://docs.oracle.com/javase/tutorial/networking/sockets/

+0

感謝斯瓦羅格。這很快,鏈接非常有幫助。 –

相關問題