//聊天软件项目TCP升级版
import java.io.*;
import java.net.*;
class TcpClient2
{
public static void main(String[] args)throws Exception
{
Socket s = new Socket("192.168.1.254",10004);
OutputStream out = s.getOutputStream();
out.write("服务端,你好".getBytes());
InputStream in = s.getInputStream();
byte[] buf = new byte[1024];
int len = in.read(buf);
System.out.println(new String(buf,0,len));
s.close();
}
} class TcpServer2
{
public static void main(String[] args) throws Exception
{
ServerSocket ss = new ServerSocket(10004);
Socket s = ss.accept();
String ip = s.getInetAddress().getHostAddress();
System.out.println(ip+"....connected");
InputStream in = s.getInputStream();
byte[] buf = new byte[1024];
int len = in.read(buf);
System.out.println(new String(buf,0,len));
OutputStream out = s.getOutputStream();
Thread.sleep(10000);
out.write("哥们收到,你也好".getBytes());
s.close();
ss.close();
}
}

最新文章

  1. 分享一下Java写的坦克大战游戏,相信很多人小时候玩过
  2. Android获取服务器Json字符串并显示在ListView上面
  3. insertion sort(插入排序)
  4. 解决:ERROR: Cannot launch Jack server
  5. velocity模板引擎学习(1)
  6. JS-DOM对象知识点汇总(慕课)
  7. CCF第四题无向图打印路径
  8. Win10 开发者模式开启
  9. 用 eric6 与 PyQt5 实现python的极速GUI编程(系列03)---- Drawing(绘图)(2)-- 画点
  10. 查看nginx版本号
  11. Android笔记:真机调试
  12. C++:FMC 错误
  13. 你好,C++(29)脚踏两只船的函数不是好函数 5.4 函数设计的基本规则
  14. 深入理解7816(4)---关于T=1
  15. python-md5加密
  16. mybatis generator 插件安装及使用
  17. mysql 报错 session halted的解决办法,实际工作中的结论。
  18. SQLServer2008数据库连接error40错误
  19. GIT工程迁移方法总结
  20. 例10-10 uva10491(简单概率)

热门文章

  1. Django1.6 +wsgi 部署到Apache2 的步骤。
  2. cannot be translated into a null value due to being declared as a primitive type. Consid
  3. 下一个时代,对话即平台 —— 开始使用Bot Framework和Cognitive Service来打造你的智能对话服务
  4. Splash 笔记
  5. CI框架中 日志输出方法log_message()只允许输出字符串解决方案
  6. GAN网络
  7. Enterprise Architect UML建模
  8. 【BZOJ】2015: [Usaco2010 Feb]Chocolate Giving(spfa)
  9. VS2008 调试出现错误 "Unable to start debugging."
  10. js和jquery获取父级元素、子级元素、兄弟元素的方法{转}