5D艺术网首页
商城
|
资讯
|
作品
|
博客
|
教程
|
论坛
登录
注册
加为好友
发短消息
来自:
性别:秘密
最后登录:2009-09-05
http://walktree.5d.cn/
首页
|
新闻
|
话题
|
博客
|
相册
|
艺术作品
|
社交关系
|
留言板
|
社交圈
2005/10/12 | socket data
类别(::键盘时代::)
|
评论
(2)
|
阅读(145)
|
发表于 23:09
get an java socket example,I want to try xmlSocket in flash.
post here for study.
Server:
import java.io.*;
import java.net.*;
public class SingleServer
{
public static void main(String args[]){
try{
ServerSocket serverObj=null;
try{
serverObj=new ServerSocket(3000);
}catch(Exception e){
System.out.println("Sorry,can not listen to"+e);
}
Socket clientObj=null;
try{
clientObj=serverObj.accept();
}catch(Exception e){
System.out.println("Error server:"+e);
}
String lineStr;
InputStreamReader streamObj1=new InputStreamReader(clientObj.getInputStream());
BufferedReader buffObj1=new BufferedReader(streamObj1);
PrintWriter outObj=new PrintWriter(clientObj.getOutputStream());
InputStreamReader streamObj2=new InputStreamReader(System.in);
BufferedReader buffObj2=new BufferedReader(streamObj2);
System.out.println("Client:"+buffObj1.readLine());
lineStr=buffObj2.readLine();
while(!lineStr.equals("finish")){
outObj.println(lineStr);
outObj.flush();
System.out.println("Server:"+lineStr);
System.out.println("Client:"+buffObj1.readLine());
lineStr=buffObj2.readLine();
}
buffObj1.close();
outObj.close();
clientObj.close();
serverObj.close();
}catch(Exception e){
System.out.println("Error:"+e);
}
}
};
------------------------------
client:
import java.io.*;
import java.net.*;
public class SingleClient
{
public static void main(String args[]){
try{
Socket socketObj = new Socket("127.0.0.1",3000);
InputStreamReader streamObj1=new InputStreamReader(System.in);
BufferedReader buffObj1=new BufferedReader(streamObj1);
PrintWriter outObj = new PrintWriter(socketObj.getOutputStream());
BufferedReader buffObj2=new BufferedReader(new InputStreamReader(socketObj.getInputStream()));
String readStr;
readStr=buffObj1.readLine();
while(!readStr.equals("finish")){
outObj.println(readStr);
outObj.flush();
System.out.println("Client:"+readStr);
System.out.println("Server:"+buffObj2.readLine());
readStr=buffObj1.readLine();
}
outObj.close();
buffObj2.close();
socketObj.close();
}catch(Exception e){
System.out.println("Error:"+e);
}
}
};
code in flash:
var mySocket = new XMLSocket();
mySocket.connect("127.0.0.1", 3000);
mySocket.onConnect = function(success) {
if (success) {
my.text="Ok";
} else {
my.text="connect failed";
}
};
I will make an exhaustive study in a week.
I hope to get a good work
0
评论
Comments
日志分类
首页
[226]
:: Flash ::
[87]
:: php ::
[8]
::眼睛和耳朵::
[36]
::键盘时代::
[73]
::水痕专栏::
[22]