7 years C/C++/C# programing, focus on embedded and mobile device development.
博客园
::
首页
::
新随笔
::
联系
::
订阅
::
管理
::
72 随笔 :: 1 文章 :: 132 评论 :: 5 引用
PDA SOAP Server探索历程(1)
仅仅是作为项目前期的调研,并不一定真的要创建自己的SOAP Server,但至少目前我对此比较感兴趣,呵呵,一切都是要从头开始。
首先熟悉TcpListener在PDA上面的应用情况,下面的例子是一个时间服务器DEMO,服务器在13端口监听传入的连接,一旦侦听到客户端的链接后,就发送时间给客户端,然后断开连接。
服务器是基于PPC的应用程序,既可以运行在PC上面,也可以运行在PDA上面,注意的是当PDA连接到PC上后,PC的网络连接会多出来一个,这个是用于和PDA通信的,相当于另外一个子网,需要注意其IP地址。源码如下:
using
System;
using
System.Collections.Generic;
using
System.ComponentModel;
using
System.Data;
using
System.Drawing;
using
System.Text;
using
System.Windows.Forms;
using
System.Net;
using
System.Net.Sockets;
using
System.IO;
namespace
PDATimeServer
{
public
partial
class
Form1 : Form
{
private
bool
done
=
false
;
TcpListener listener
=
null
;
public
Form1()
{
InitializeComponent();
}
private
void
button1_Click(
object
sender, EventArgs e)
{
listener
=
new
TcpListener(IPAddress.Parse(comboBox1.Text.Trim()),
13
);
listener.Start();
done
=
false
;
while
(
!
done)
{
int
index
=
listBox1.Items.Add(
"
Waiting for connection
"
);
while
(
false
==
listener.Pending()
&&
false
==
done)
{
Application.DoEvents();
}
if
(done)
break
;
TcpClient client
=
listener.AcceptTcpClient();
listBox1.Items[index]
+=
"
Connection accepted.
"
;
NetworkStream ns
=
client.GetStream();
StreamWriter writer
=
new
StreamWriter(ns);
writer.Write(DateTime.Now);
writer.Close();
ns.Close();
client.Close();
}
listener.Stop();
listBox1.Items.Add(
"
Stop listening
"
);
}
private
void
button2_Click(
object
sender, EventArgs e)
{
done
=
true
;
}
private
void
Form1_Load(
object
sender, EventArgs e)
{
IPAddress[] ipList
=
Dns.GetHostByName(Dns.GetHostName()).AddressList;
foreach
(IPAddress ip
in
ipList)
{
comboBox1.Items.Add(ip);
}
comboBox1.SelectedIndex
=
0
;
}
}
}
客户端为了方便测试,是基于Windows的,不能运行在PDA上面,它的功能就是连接到指定的服务器并获取时间。源码如下:
using
System;
using
System.Collections.Generic;
using
System.ComponentModel;
using
System.Data;
using
System.Drawing;
using
System.Text;
using
System.Windows.Forms;
using
System.Net;
using
System.Net.Sockets;
using
System.IO;
namespace
TimeClient
{
public
partial
class
Form1 : Form
{
public
Form1()
{
InitializeComponent();
}
private
void
button1_Click(
object
sender, EventArgs e)
{
TcpClient client
=
new
TcpClient();
client.Connect(comboBox1.Text.Trim(),
13
);
NetworkStream stream
=
client.GetStream();
StreamReader reader
=
new
StreamReader(stream);
textBox1.Text
=
reader.ReadLine();
reader.Close();
stream.Close();
client.Close();
}
private
void
Form1_Load(
object
sender, EventArgs e)
{
IPAddress[] ipList
=
Dns.GetHostByName(Dns.GetHostName()).AddressList;
foreach
(IPAddress ip
in
ipList)
{
comboBox1.Items.Add(ip);
}
comboBox1.Items.Add(IPAddress.Parse(
"
169.254.2.1
"
));
comboBox1.SelectedIndex
=
0
;
}
}
}
绿色通道:
好文要顶
关注我
收藏该文
与我联系
posted on 2006-11-17 11:57
woaiusd
阅读(1099)
评论(0)
编辑
收藏
注册用户登录后才能发表评论,请
登录
或
注册
,
返回博客园首页
。
首页
博问
闪存
新闻
园子
招聘
知识库
最新IT新闻
:
·
春节后礼品回收iPhone成新宠燕窝被冷落
·
分析称苹果近1000亿现金储备最佳用途是派息
·
扎克伯格11件蠢事:曾同意将Facebook卖给雅虎
·
最想要的Entity Framework功能
·
专访Jeffrey Richter:Windows 8是微软的重中之重
»
更多新闻...
最新知识库文章
:
·
高级编程语言的发展历程
·
如何学习一门新的编程语言?
·
学习不同编程语言的重要性
·
为什么我喜欢富于表达性的编程语言
·
计算机专业的女生为什么要学编程
»
更多知识库文章...
China-pub 2011秋季教材巡展
China-Pub 计算机绝版图书按需印刷服务
<
2012年2月
>
日
一
二
三
四
五
六
29
30
31
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
1
2
3
4
5
6
7
8
9
10
公告
昵称:
woaiusd
园龄:
5年3个月
粉丝:
1
关注:
0
搜索
常用链接
我的随笔
我的评论
我的参与
最新评论
我的标签
最新随笔
1. MAC OS中的dylib 的@rpath和@loader_path小问题
2. 有几个人知道C语言中int8_t, uint8_t, time_t ... 等等数据类型中的_t是什么意思
3. 无线路由器总是提示输入的密码错误
4. I2C中的重复起始条件到底是什么意思
5. release, retain, autorelease 与 AT, MT, AMT
6. 有关 stringWithString 和 initWithString
7. lpc1343 usb isp not work in linux and mac
8. C#平台互操作部署问题
9. C++Builder中的异常传递
10. Windows mobile 中获取内存使用情况
我的标签
m3
(1)
windows7
(1)
paint
(1)
玩玩Hiweed linux 2.0
(1)
玩玩edubuntu 8.10
(1)
kubuntu
(1)
淘宝
(1)
taobao
(1)
api
(1)
淘宝API
(1)
更多
随笔分类
.Net
(rss)
Linux(4)
(rss)
Office使用及开发(4)
(rss)
嵌入式设备(5)
(rss)
射频识别(2)
(rss)
移动设备(26)
(rss)
资料查阅(8)
(rss)
随笔档案
2011年8月 (1)
2011年6月 (1)
2011年4月 (2)
2011年3月 (2)
2010年12月 (2)
2010年3月 (1)
2009年9月 (1)
2009年7月 (2)
2008年11月 (5)
2008年9月 (4)
2008年8月 (2)
2008年2月 (1)
2008年1月 (3)
2007年9月 (1)
2007年8月 (4)
2007年5月 (1)
2007年4月 (1)
2007年3月 (6)
2007年2月 (2)
2007年1月 (3)
2006年12月 (9)
2006年11月 (18)
友情链接
swnuwangyun
我在CSDN上的老窝
yutian
我们寝室的室长,大牛!
最新评论
评论排行榜