当前位置:首页 » 操作系统 » 安卓服务器源码

安卓服务器源码

发布时间: 2022-09-13 14:48:22

① 在Android端使用socket传输图片到java服务器,求源代码

/**
*思想:
1.直接将所有数据安装字节数组发送
2.对象序列化方式
*/

/**
*thread方式
*
*@authorAdministrator
*/
{
privatestaticfinalintFINISH=0;
privateButtonsend=null;
privateTextViewinfo=null;
privateHandlermyHandler=newHandler(){
@Override
publicvoidhandleMessage(Messagemsg){
switch(msg.what){
caseFINISH:
Stringresult=msg.obj.toString();//取出数据
if("true".equals(result)){
TestSocketActivity4.this.info.setText("操作成功!");
}else{
TestSocketActivity4.this.info.setText("操作失败!");
}
break;
}
}
};


@Override
publicvoidonCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);
super.setContentView(R.layout.activity_test_sokect_activity4);
//StrictMode.setThreadPolicy(newStrictMode.ThreadPolicy.Builder()
//.detectDiskReads().detectDiskWrites().detectNetwork()
//.penaltyLog().build());
//StrictMode.setVmPolicy(newStrictMode.VmPolicy.Builder()
//.detectLeakedSqlLiteObjects().detectLeakedClosableObjects()
//.penaltyLog().penaltyDeath().build());

this.send=(Button)super.findViewById(R.id.send);
this.info=(TextView)super.findViewById(R.id.info);
this.send.setOnClickListener(newSendOnClickListener());
}

{
@Override
publicvoidonClick(Viewv){
try{
newThread(newRunnable(){
@Override
publicvoidrun(){
try{
//1:
Socketclient=newSocket("192.168.1.165",9898);
//2:
ObjectOutputStreamoos=newObjectOutputStream(
client.getOutputStream());
//3:
UploadFilemyFile=SendOnClickListener.this
.getUploadFile();
//4:
oos.writeObject(myFile);//写文件对象
//oos.writeObject(null);//避免EOFException
oos.close();


BufferedReaderbuf=newBufferedReader(
newInputStreamReader(client
.getInputStream()));//读取返回的数据
Stringstr=buf.readLine();//读取数据
Messagemsg=TestSocketActivity4.this.myHandler
.obtainMessage(FINISH,str);
TestSocketActivity4.this.myHandler.sendMessage(msg);
buf.close();
client.close();
}catch(Exceptione){
Log.i("UploadFile",e.getMessage());
}
}
}).start();
}catch(Exceptione){
e.printStackTrace();
}
}

()throwsException{//包装了传送数据
UploadFilemyFile=newUploadFile();
myFile.setTitle("tangcco安卓之Socket的通信");//设置标题
myFile.setMimeType("image/png");//图片的类型
Filefile=newFile(Environment.getExternalStorageDirectory()
.toString()
+File.separator
+"Pictures"
+File.separator
+"b.png");
InputStreaminput=null;
try{
input=newFileInputStream(file);//从文件中读取
ByteArrayOutputStreambos=newByteArrayOutputStream();
bytedata[]=newbyte[1024];
intlen=0;
while((len=input.read(data))!=-1){
bos.write(data,0,len);
}
myFile.setContentData(bos.toByteArray());
myFile.setContentLength(file.length());
myFile.setExt("png");
}catch(Exceptione){
throwe;
}finally{
input.close();
}
returnmyFile;
}
}

}{
privateStringtitle;
privatebyte[]contentData;
privateStringmimeType;
privatelongcontentLength;
privateStringext;

publicStringgetTitle(){
returntitle;
}

publicvoidsetTitle(Stringtitle){
this.title=title;
}

publicbyte[]getContentData(){
returncontentData;
}

publicvoidsetContentData(byte[]contentData){
this.contentData=contentData;
}

publicStringgetMimeType(){
returnmimeType;
}

publicvoidsetMimeType(StringmimeType){
this.mimeType=mimeType;
}

publiclonggetContentLength(){
returncontentLength;
}

publicvoidsetContentLength(longcontentLength){
this.contentLength=contentLength;
}

publicStringgetExt(){
returnext;
}

publicvoidsetExt(Stringext){
this.ext=ext;
}

}

下边是服务端

publicclassMain4{
publicstaticvoidmain(String[]args)throwsException{
ServerSocketserver=newServerSocket(9898);//服务器端端口
System.out.println("服务启动........................");
booleanflag=true;//定义标记,可以一直死循环
while(flag){//通过标记判断循环
newThread(newServerThreadUtil(server.accept())).start();//启动线程
}
server.close();//关闭服务器
}
}


{
="D:"+File.separator+"myfile"
+File.separator;//目录路径
privateSocketclient=null;
privateUploadFileupload=null;

publicServerThreadUtil(Socketclient){
this.client=client;
System.out.println("新的客户端连接...");
}

@Override
publicvoidrun(){
try{
ObjectInputStreamois=newObjectInputStream(
client.getInputStream());//反序列化
this.upload=(UploadFile)ois.readObject();//读取对象//UploadFile需要和客户端传递过来的包名类名相同,如果不同则会报异常
System.out.println("文件标题:"+this.upload.getTitle());
System.out.println("文件类型:"+this.upload.getMimeType());
System.out.println("文件大小:"+this.upload.getContentLength());

PrintStreamout=newPrintStream(this.client.getOutputStream());//BufferedWriter
out.print(this.saveFile());//返回响应
// BufferedWriterwriter=null;
// writer.write("");
}catch(Exceptione){
e.printStackTrace();
}finally{
try{
this.client.close();
}catch(IOExceptione){
e.printStackTrace();
}
}
}

privatebooleansaveFile()throwsException{//负责文件内容的保存
/**
*java.util.UUID.randomUUID():
*UUID.randomUUID().toString()是javaJDK提供的一个自动生成主键的方法。UUID(Universally
*UniqueIdentifier)全局唯一标识符,是指在一台机器上生成的数字,它保证对在同一时空中的所有机器都是唯一的,
*是由一个十六位的数字组成
*,表现出来的形式。由以下几部分的组合:当前日期和时间(UUID的第一个部分与时间有关,如果你在生成一个UUID之后,
*过几秒又生成一个UUID,
*则第一个部分不同,其余相同),时钟序列,全局唯一的IEEE机器识别号(如果有网卡,从网卡获得,没有网卡以其他方式获得
*),UUID的唯一缺陷在于生成的结果串会比较长,字符串长度为36。
*
*UUID.randomUUID().toString()是javaJDK提供的一个自动生成主键的方法。UUID(Universally
*UniqueIdentifier)全局唯一标识符,是指在一台机器上生成的数字,它保证对在同一时空中的所有机器都是唯一的,
*是由一个十六位的数字组成,表现出来的形式
*/
Filefile=newFile(DIRPATH+UUID.randomUUID()+"."
+this.upload.getExt());
if(!file.getParentFile().exists()){
file.getParentFile().mkdir();
}
OutputStreamoutput=null;
try{
output=newFileOutputStream(file);
output.write(this.upload.getContentData());
returntrue;
}catch(Exceptione){
throwe;
}finally{
output.close();
}
}
}{
privateStringtitle;
privatebyte[]contentData;
privateStringmimeType;
privatelongcontentLength;
privateStringext;

publicStringgetTitle(){
returntitle;
}

publicvoidsetTitle(Stringtitle){
this.title=title;
}

publicbyte[]getContentData(){
returncontentData;
}

publicvoidsetContentData(byte[]contentData){
this.contentData=contentData;
}

publicStringgetMimeType(){
returnmimeType;
}

publicvoidsetMimeType(StringmimeType){
this.mimeType=mimeType;
}

publiclonggetContentLength(){
returncontentLength;
}

publicvoidsetContentLength(longcontentLength){
this.contentLength=contentLength;
}

publicStringgetExt(){
returnext;
}

publicvoidsetExt(Stringext){
this.ext=ext;
}

}

② 谁有Android系统的源码

1、通过 ubuntu 软件中心安装 wine;
2、通过 ubuntu 软件中心安装 winetricks;
3、通过 winetricks 在 shell中输入: winetricks mfc42

1、通过 wine windows 的方式启动代理服务器
2、设置浏览器代理服务器
3、设置shell代理服务器:
在shell中输入 sudo gedit /etc/bash.bashrc
在文件 /etc/bash.bashrc 中添加:如下内容
export http_proxy=http://127.0.0.1:8580/export https_proxy=http://127.0.0.1:8580/

通过shell安装如下的组件:
1、sudo apt-get install bison g++-multilib git gperf libxml2-utils
2、新建一个存放源码的目录,如:mkdir ~/andorid/source
3、在源码目录中输入命令:repo init -u https://android.googlesource.com/platform/manifest -b android-4.0.1_r1
其中: android-4.0.1_r1是android源码的版本,更多的版本可以通过下面的方式查询:http://source.android.com/source/build-numbers.html

4、修改source/.repo/manifest/default.xml 文件中的 fetch 的值为:
git://Android.git.linaro.org/

通过如下的指令来设置邮箱和用户名
git config --global user.name "<your name>" ----修改用户名git config --global user.email "<your email>" ----修改email

5、在source目录下输入指令:repo sync
便开始了代码的下载

③ 如何调试跟踪Android Framework源代码

本文讲解如何在Eclipse中导入Android源代码(包括Framework和Application的代码),然后通过模拟器或真机跟踪/调试Android的Java代码,区别于一般基于Android SDK的纯应用开发,这里可以跟踪/调试Framework中的代码。

一、准备工作

确保机器上已经安装并配置下列软件环境:JDK/ Eclipse / Android SDK / ADT

即,机器上已经安装了Eclipse下Android应用开发所需的环境。如果还未配置,移步《搭建Windows下Android应用开发环境——Eclipse/Android/ADT》。

另外,为了跟踪调试Android源码,你还需要有Android源码,并有源码的编译环境,可以是:

  • 虚拟机环境 虚拟机中安装Linux,Linux下编译Android源码。此环境下,如果要在宿主机的Eclipse中调试,还需要把Android的源码路径共享出来,宿主机可访问到;

  • 有单独的可编译Android的网络环境 在你的客户端的机器上访问服务器共享出来的Android的源码路径;

  • Linux环境下直接通过Eclipse跟踪调试本机上的Android源码。

  • 注意:不管哪种工作方式,Android源码要都是已经编译过的,且编译时采用的是Eng模式(vs User mode)。编译Android Platform和Kernel的过程,可参考《Ubuntu10.10下编译Android2.2平台》及《Ubuntu10.10下编译Android2.2内核》。

    二、基本设置

    准备工作完毕之后,现在做一些基本的设置。

    1. 把Android源码路径<Android_ROOT>下的developmentideeclipse中的.classpath文件复制到<Android_ROOT>下;如果需要在模拟器中进行调试的话,需要复制三个img(具体方法见http://wenku..com/view/26d9063c87c24028915fc366.html)

    2. 修改Eclipse的设置

    修改eclipse.ini文件,更改下列内容:

    [plain]view plain

  • -Xms40m

  • -Xmx384m

  • 改为:

    [java]view plain

  • -Xms128m

  • -Xmx512m

  • 这里增大最小Java堆大小到128MB,增大最大Java堆大小到512MB。

    三、Eclipse中创建工程

    1. File > New > Java Project

④ 哪里可以找到带服务器端的安卓项目源码

Android平台的即时通讯软件实现,使用Socket进行通讯,利用PC作为服务器作为消息转发的平台,若好友在线,服务器则直接将消息转发给好友;若好友离线,服务器会将该消息暂存在服务器端,当消息的接收者登陆到系统后,再将该离线消息发给接收者

⑤ 在网上下载了一个安卓项目的源码 有客户端 服务器端 数据库备份,不知道应该怎么配置起来

是不是ip没改 ip要连你本机的IP 才能找到服务器的servlet

⑥ 网上下载的安卓服务器端源码怎么运行,要装什么软件,导入什么包

感觉又是一个做毕业设计的。。。android端用eclipse软件,装android adt插件,需要android sdk,然后配置下系统环境,网络有具体方法,我就不复制去了。服务器端的你应该是用的tomcat?这要看你服务器都有啥功能了,连接啥数据库,或者用到上传下载,或者需要xml,或者exl,都需要不同的包

⑦ androidpn服务端源码修改后怎么编译

1.服务器:
ConfigManager--配置信息加载类,
Config--配置信息管理类,可以得到配置文件中指定属性的值;
CopyMessageUtil--将IQ中的id得到赋值给回执对象;
AuthManager--提供用户认证的相关功能;
IQAuthHandler--接收并处理命名空间为“jabber:iq:auth”的消息请求,用于处理用户验证业务;
IQRegisterHandler--接收并处理命名空间为 "jabber:iq:register"的消息请求,用于处理用户注册业务;
IQRosterHandler--接收处理命名空间为"jabber:iq:roster"的消息请求,用于处理用户获取花名册业务;--未提供实现,如需此功能需要扩展;
PresenceUpdateHandler--接收处理用户的状态变更请求信息;
Connection--一个XMPP连接服务器的实例,提供发送消息及得到服务器连接相关信息;
ConnectionCloseListener--客户端与服务器之间的连接断开监听器;
StanzaHandler--一个消息处理类,处理传入的XML节,把接收到的消息转换成一个XML的对象;
XmppIoHandler--继承于MINA中的IOHandler,用于从MINA中接收消息,并把消息交给StanzaHandler类处理;
PresenceManager--用于管理用户的在线状态;
NotificationManager--消息通知发送管理类,提供了发送消息给客户端的功能:
A.sendBroadcast--给所有在线用户发送消息;
B.sendNotifcationToUser--给指定用户发送消息 ;
C.sendNotifications--给指定的多个或一个用户发送消息;
D.sendOfflineNotification--发送离线消息;
IQRouter--IQ请求路由类,继承了IQHandler的IQ消息处理类需要在IQRouter类中注册,IQRounter就会跟命名空间把消息路由到相应的处理类中去处理;
MessageRouter--Message消息路由类;
PresenceRouter--Presence消息路由类;
PacketDeliverer--发送到连接的会话;
PacketRouter--Packet路由类,在这个类里有IQRouter、PresenceRouter、MessageRouter三个类的对象,可以对三种类型的消息都可以进行处理路由;
ClientSession--代表一个客户端与服务器之间的连接;从这个连接中可以得到这个连接的相关信息,如用户名,状态等;
SessionManager--管理所有与服务器之间的连接;

服务器端接收客户端消息处理流程:

2.Android端:
NotificationService类--后台运行并响应来自服务器的事件推送通知服务;
ServiceManager类--加载客户端中的配置信息,并管理NotifactionService服务的启动与关闭;
XmppManager类--管理客户端和服务器之间的连接,向服务器发送连接、注册、登陆请求任务;
NotificationDetailsActivity --用于终端接收到的通知详细视图显示;
NotificationIQ--通知实体;
NotificationIQProvider--一个xml的处理类,负责把一个xml结构的消息内容转换成一个NotificationIQ通知实体对象;
NotificationPacketListener---接收从服务器端推送过来的Packet;
NotificationSettingsActivity--设置信息;
NotificationReceiver--推送通知消息的广播接收器;
PersistentConnectionListener--监控客户端与服务器之间的连接关闭和重新连接事件;
PhoneStateChangeListener--监听手机状态;
ConnectivityReceiver--网络变化广播接收器;

PacketReader--从MINA中读取推送过来的信息;
PacketWriter--向MINA中写入回执信息;

接收消息处理流程:

PacketReader
init():
readerThread = new Thread() {
public void run() {
parsePackets(this);
}
};
-》parsePackets
-》processPacket
-》NotificationPacketListener
-》NotificationIQProvider
-》NotificatioIQ
-》Intent
-》发送回执、发出接收到消息的广播
-》点击消息的时候,再次给服务端发送一个查看请求,修改服务器中消息的状态;

如果服务端发送一个message类型的消息到客户端后,客户端是无法处理的。
也就是说客户端可以发送不同类型的消息到服务端,但是却不能处理服务端发回的除IQ认证消息以外的其他类型的消息。
如果需要扩展,需要在NotificationPacketListener类中加入处理逻辑,并提供相应的Provider、消息实体及后续处理逻辑。

⑧ 如何导入与配置从网上下载的android源代码及服务器端源代码

将Android项目导入import进Eclipse。 注意SDK版本是否匹配 。 服务器部署到Tomcat下。 你得在数据库中将这个点菜系统的数据库和表建好,或者导入。在服务器的代码中修改好你的数据库名和密码。

⑨ 如何编辑android 系统源码

1、通过 ubuntu 软件中心安装 wine;
2、通过 ubuntu 软件中心安装 winetricks;
3、通过 winetricks 在 shell中输入: winetricks mfc42

1、通过 wine windows 的方式启动代理服务器
2、设置浏览器代理服务器
3、设置shell代理服务器:
在shell中输入 sudo gedit /etc/bash.bashrc
在文件 /etc/bash.bashrc 中添加

通过shell安装如下的组件:
1、sudo apt-get install bison g++-multilib git gperf libxml2-utils
2、新建一个存放源码的目录,如:mkdir ~/andorid/source
3、在源码目录中输入命令:repo init -u -b android-4.0.1_r1
其中: android-4.0.1_r1是android源码的版本,更多的版本可以通过下面的方式查询:

4、修改source/.repo/manifest/default.xml 文件中的 fetch 的值为:
git://Android.git.linaro.org/

通过如下的指令来设置邮箱和用户名
git config --global user.name "<your name>" ----修改用户名git config --global user.email "<your email>" ----修改email
5、在source目录下输入指令:repo sync
便开始了代码的下载
方便他人亦是方便自己,如果觉得还行就点下下边的投票吧,这样可以帮助其他人更快的找到解决问题的方法;有疑问的也可留言哦, 谢谢!

⑩ 求带有客户端和服务器端的Android应用程序源代码(能运行的),谢谢

这是我个人的一个项目,客户端,服务端以及数据库都有。

热点内容
怎么设置电脑开机密码和屏幕锁 发布:2025-05-16 03:07:05 浏览:55
华为锁屏密码忘记了怎么解锁 发布:2025-05-16 03:06:26 浏览:474
安卓文字为什么没有苹果舒服 发布:2025-05-16 03:01:26 浏览:357
phpnow解压版 发布:2025-05-16 02:52:49 浏览:811
dmporacle数据库 发布:2025-05-16 02:44:31 浏览:831
云主机上传 发布:2025-05-16 02:44:30 浏览:82
鼠标如何编程 发布:2025-05-16 02:29:09 浏览:816
安卓70能用什么软件 发布:2025-05-16 01:45:09 浏览:481
编程发展史 发布:2025-05-16 01:38:52 浏览:529
android图片气泡 发布:2025-05-16 01:38:40 浏览:887