Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Java SE 综合讨论区 » 实战错误讨论  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 服务与客户之间通信的问题?(传递中文,出现乱码)
nextsun





发贴: 5
积分: 0
于 2006-05-31 15:10 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
就是不能够用传递中文,出现乱码"?????",求大家帮帮我!!!

//服务器程序
import java.io.*;
import java.net.*;
public class tcpserver
{
public static void main(String[] args) throws IOException
{
ServerSocket svrsoc=null;
Socket soc=null;
DataInputStream in=null;
PrintStream out=null;
InetAddress clientIP=null;
String str=null;
try
{
svrsoc=new ServerSocket(5555);
System.out.println("Server start....");
soc=svrsoc.accept();

in=new DataInputStream(soc.getInputStream());
out=new PrintStream(soc.getOutputStream());
clientIP=soc.getInetAddress();
System.out.println("Client's IP address:"+clientIP);
System.out.println("Port:"+soc.getLocalPort());
System.out.println("Client's Name:"+soc.getInetAddress().getHostName());
out.println("welcome.....");
in.readLine();
while (!str.equals("quit"))
{
System.out.println("Client said:"+str);
str=in.readLine();
}
System.out.println("Client want to leave");
}
catch(Exception e)
{
System.out.println("error:"+e);
}
finally
{
in.close();
out.close();
soc.close();
svrsoc.close();
System.exit(0);
}
}
}
//客户机程序
import java.io.*;
import java.net.*;
public class tcpclient
{
public static void main(String[] args) throws IOException
{
Socket soc=null;
DataInputStream in=null;
PrintStream out=null;
DataInputStream sysin=null;
String strin=null;
String strout=null;
try
{
soc=new Socket("127.0.0.1",5555);
System.out.println("Connecting to the Server");
in=new DataInputStream(soc.getInputStream());
out=new PrintStream(soc.getOutputStream());
strin=in.readLine();
System.out.println("Server said:"+strin);
sysin=new DataInputStream(System.in);
strout=sysin.readLine();
while (!strout.equals("quit"))
{
out.println(strout);
strout=sysin.readLine();
}
out.println(strout);
}
catch(Exception e)
{
System.out.println("error:"+e);
}
finally
{
in.close();
out.close();
sysin.close();
soc.close();
System.exit(0);
}
}
}


why edited on 2006-05-31 19:33


25了才开始学JAVA晚吗?

话题树型展开
人气 标题 作者 字数 发贴时间
7886 服务与客户之间通信的问题?(传递中文,出现乱码) nextsun 2713 2006-05-31 15:10
6220 Re:服务与客户之间通信的问题? nextsun 28 2006-05-31 16:45
6184 Re:服务与客户之间通信的问题?(传递中文,出现乱码) lisliefor 2259 2006-06-01 11:11
6235 Re:服务与客户之间通信的问题?(传递中文,出现乱码) lisliefor 147 2006-06-01 11:12
6215 Re:服务与客户之间通信的问题?(传递中文,出现乱码) nextsun 29 2006-06-01 12:55
6812 Re:服务与客户之间通信的问题?(传递中文,出现乱码) nextsun 84 2006-06-01 12:57

flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923