俊星的BLOG
導航
BlogJava
首頁
新隨筆
聯系
聚合
管理
<
2009年5月
>
日
一
二
三
四
五
六
26
27
28
29
30
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
30
31
1
2
3
4
5
6
統計
隨筆 - 50
文章 - 0
評論 - 6
引用 - 0
常用鏈接
我的隨筆
我的評論
我的參與
最新評論
留言簿
(1)
給我留言
查看公開留言
查看私人留言
隨筆分類
代碼庫(7)
(rss)
隨筆檔案
2010年11月 (3)
2010年10月 (12)
2009年6月 (5)
2009年5月 (22)
2009年4月 (8)
最新隨筆
1.?實現變更統計
2.?切換IE8中碰到的問題
3.?發布FWMS
4.?ActiveMQ初探
5.?CAS初步配置
搜索
最新評論
1.?re: JAVA圖像縮放處理[未登錄]
不錯的方法
--test
2.?re: freetts初探
學習了! 就是不清楚為啥在eclipse下跑不起來...
--apiao
3.?re: freetts初探
System property "mbrola.base" is undefined. Will not use MBROLA voices.
這個問題怎么解決啊?
--瓏兒
4.?re: ActiveMQ初探
測試通過。多謝
--71569973
5.?登錄網站
評論內容較長,點擊標題查看
--ahome
閱讀排行榜
1.?ftp的port和pasv模式(轉)(8036)
2.?JAVA圖像縮放處理(4187)
3.?Nutz初步試用(4110)
4.?Window下FTP命令使用(3523)
5.?freetts初探(3435)
6.?ActiveMQ初探(2910)
7.?MYSQL Access denied 問題的解決(2347)
8.?HTTP Client及HTTPS初探(1993)
9.?JAVA單向加密(MD5,SHA,MAC)(1269)
10.?CAS認證初探(1158)
評論排行榜
1.?freetts初探(2)
2.?HTTP Client及HTTPS初探(2)
3.?ActiveMQ初探(1)
4.?JAVA圖像縮放處理(1)
5.?我的DWR之DefaultContainer(0)
我的JAVA工具之網絡傳輸對象
import
java.io.ObjectInputStream;
import
java.io.ObjectOutputStream;
import
java.io.Serializable;
import
java.net.ServerSocket;
import
java.net.Socket;
public
class
Tet
{
public
static
void
main(String[] args)
{
new
Server().start();
new
Client().start();
}
}
class
TestVO
implements
Serializable
{
private
String name;
private
int
id;
public
TestVO(
int
id, String name)
{
super
();
this
.id
=
id;
this
.name
=
name;
}
public
String toString()
{
return
"
id:
"
+
id
+
"
name:
"
+
name;
}
}
class
Client
extends
Thread
{
public
void
run()
{
try
{
Socket client
=
new
Socket(
"
localhost
"
,
8888
);
ObjectInputStream ois
=
new
ObjectInputStream(client.getInputStream());
TestVO vo
=
(TestVO) ois.readObject();
System.out.println(
"
client read:
"
+
vo);
ois.close();
client.close();
}
catch
(Exception e)
{
//
TODO: handle exception
e.printStackTrace();
}
}
}
class
Server
extends
Thread
{
public
void
run()
{
try
{
ServerSocket ss
=
new
ServerSocket(
8888
);
Socket server
=
ss.accept();
ObjectOutputStream oos
=
new
ObjectOutputStream(server.getOutputStream());
TestVO vo
=
new
TestVO(
1
,
"
good job
"
);
oos.writeObject(vo);
System.out.println(
"
server write:
"
+
vo);
oos.close();
server.close();
ss.close();
}
catch
(Exception e)
{
//
TODO: handle exception
}
}
}
輸出:
server write:id:
1
name:good job
client read:id:
1
name:good job
posted on 2009-05-19 21:40
俊星
閱讀(575)
評論(0)
編輯
收藏
新用戶注冊
刷新評論列表
只有注冊用戶
登錄
后才能發表評論。
網站導航:
博客園
IT新聞
Chat2DB
C++博客
博問
管理
Powered by:
BlogJava
Copyright © 俊星
主站蜘蛛池模板:
海伦市
|
顺义区
|
香河县
|
如皋市
|
浦北县
|
奉化市
|
和政县
|
沅陵县
|
恭城
|
西乡县
|
门源
|
平果县
|
长春市
|
宝应县
|
泾川县
|
杭锦旗
|
普陀区
|
青浦区
|
锦州市
|
桂阳县
|
盱眙县
|
马公市
|
皮山县
|
揭西县
|
合川市
|
沅陵县
|
西青区
|
永平县
|
凤台县
|
成安县
|
南和县
|
拉孜县
|
安泽县
|
雷波县
|
佛坪县
|
崇文区
|
牙克石市
|
乌恰县
|
五家渠市
|
通山县
|
连平县
|