我已經到處搜尋找到這個問題的答案:TCP連接使用Visual Basic .NET服務器發送和接收的Java/Android的
我有一個TCP客戶端在我的Android應用程序,它可以發送消息到服務器這是寫在Visual Basic .NET Framework 4的
現在我想從我的服務器發送消息到手機通過3G,它適用於WiFi和3G ..
private class startserver extends Thread
{
public void server() throws Exception
{
String clientSentence;
String capitalizedSentence;
ServerSocket welcomeSocket = new ServerSocket(8765);
while(true)
{
Socket connectionSocket = welcomeSocket.accept();
BufferedReader inFromClient =
new BufferedReader(new InputStreamReader(connectionSocket.getInputStream()));
DataOutputStream outToClient = new DataOutputStream(connectionSocket.getOutputStream());
clientSentence = inFromClient.readLine();
System.out.println(clientSentence.substring(1));
msgshower = clientSentence.substring(1);
MainActivity.this.runOnUiThread(new Runnable() {
public void run() {
Toast.makeText(MainActivity.this, "Received: " + msgshower , Toast.LENGTH_LONG).show();
}
});
capitalizedSentence = clientSentence.toUpperCase() + '\n';
outToClient.writeBytes(capitalizedSentence);
}
}
@Override
public void run() {
try {
server();
} catch (Exception e) {
e.printStackTrace();
}
}
我開始它OnCreate方法
現在我與發送(VB.NET)
Private Sub sends(ByVal message As String)
Dim tcp As New TcpClient
tcp.Connect(connectedIP, 8765)
Dim bw As New IO.BinaryWriter(tcp.GetStream)
bw.Write(message)
bw.Close()
tcp.Close()
End Sub
在WiFi就會到達,一個消息就不會3g的它...任何想法是如何做到這一點?
其他應用程序如何將其歸檔?
如何從VB連接到IP地址? – BWitched 2012-03-24 18:59:24
已連接的IP, '昏暗聽者作爲的TcpListener = CTYPE(ar.AsyncState,的TcpListener) 昏暗ClientSocket的作爲的TcpClient = listener.EndAcceptTcpClient(AR) 昏暗數據 昏暗RCVDATA作爲新IO.StreamReader(ClientSocket的。 GetStream) 數據= rcvData.ReadLine connectedIP = clientSocket.Client.RemoteEndPoint.ToString.Split( 「:」)(0) rcvData.Close() clientSocket.Close()' – Marco 2012-03-25 00:44:29