Android 模拟器和PC用 sockets 通讯
2010-03-26 06:02:00 来源:WEB开发网核心提示://向服务器发送消息PrintWriter out = new PrintWriter( new BufferedWriter( new OutputStreamWriter(client.getOutputStream())),true);out.println("server message")
//向服务器发送消息
PrintWriter out = new PrintWriter( new BufferedWriter( new OutputStreamWriter(client.getOutputStream())),true);
out.println("server message");
//关闭流
out.close();
in.close();
}
catch (Exception e)
{
System.out.println(e.getMessage());
e.printStackTrace();
}
finally
{
//关闭
client.close();
System.out.println("close");
}
}
}
catch (Exception e)
{
System.out.println(e.getMessage());
}
}
//main函数,开启服务器
public static void main(String a[])
{
Thread desktopServerThread = new Thread(new Server());
desktopServerThread.start();
}
}
更多精彩
赞助商链接