WEB开发网
开发学院手机开发Android 开发 Windows客户端与Android服务端的Socket通信 阅读

Windows客户端与Android服务端的Socket通信

 2010-06-04 14:09:00 来源:WEB开发网   
核心提示:e.printStackTrace();}}private void openUrl(String url){Uri uri = Uri.parse(url);Intent intent = new Intent(Intent.ACTION_VIEW, uri);startActivity(intent);}}2、C#

e.printStackTrace();

}

}

private void openUrl(String url)

{

Uri uri = Uri.parse(url);

Intent intent = new Intent(Intent.ACTION_VIEW, uri);

startActivity(intent);

}

}

2、C#客户端:

view plaincopy to clipboardprint?

using System;

using System.Collections.Generic;

using System.Text;

using System.Net.Sockets;

using System.Diagnostics;

namespace G3Exp.Class

{

public static class clsAndroid

{

static private void Connect(String server, String message)

{

try

{

//通过SDK下面的ADB命令来通知Android开侦听10086端口

Process p = new Process();

p.StartInfo.FileName = AppDomain.CurrentDomain.BaseDirectory+@" oolsadb.exe";

p.StartInfo.Arguments = "forward tcp:12580 tcp:10086";

p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;

p.Start();

Int32 port = 12580;

TcpClient client = new TcpClient(server, port);

//把URL发给TCP服务端

Byte[] data = System.Text.Encoding.ASCII.GetBytes(message);

NetworkStream stream = client.GetStream();

stream.Write(data, 0, data.Length);

client.Close();

}

catch (ArgumentNullException e)

{

Console.WriteLine("ArgumentNullException: {0}", e);

}

catch (SocketException e)

{

Console.WriteLine("SocketException: {0}", e);

}

}

public static void OpenWeb(string strUrl)

{

Connect("127.0.0.1", strUrl);

}

}

}

using System;

using System.Collections.Generic;

using System.Text;

using System.Net.Sockets;

上一页  1 2 3 4  下一页

Tags:Windows 客户端 Android

编辑录入:coldstar [复制链接] [打 印]
赞助商链接