程序分两部分,服务端和客户端。先把服务端运行起来,在运行客户端。整个过程就是客户端想服务端发送String,服务端再返回。客户端的String由键盘输入得到。
女装品牌排行榜
package net.tcp;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.Socket;
public class Client extends Thread
{
Socket sk = null;
BufferedReader reader = null;
PrintWriter wtr = null;
BufferedReader keyin = null;
public Client()
{
keyin = new BufferedReader(new InputStreamReader(System.in));
try
在生存模式的endless里, 各位都是如何布置阵型的?
{
sk = new Socket("127.0.0.1", 1987);
}
catch (Exception e)
{
e.printStackTrace();
}
}
public void run()
{
try
{
reader = new BufferedReader(new InputStreamReader(sk
.getInputStream()));
wtr = new PrintWriter(sk.getOutputStream());
String get = keyin.readLine();
while (true)
{
if (get != null & get.length() > 0)
洛克王国暴角龙配招
{
wtr.println(get);
wtr.flush();
// wtr.close();
// System.out.println(get + "发送完毕");
}
if (reader != null)
{
String line = reader.readLine();
System.out.println("从服务器来的信息:" + line);
}
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
public static void main(String [] args)
{
new Client().start();
}
}
posted on 2011-04-14 10:26
墙头草 阅读(1409)
评论(0) 编辑 收藏