聊天软件项目TCP升级版
2024-10-20 09:26:03
//聊天软件项目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();
}
}
最新文章
- 分享一下Java写的坦克大战游戏,相信很多人小时候玩过
- Android获取服务器Json字符串并显示在ListView上面
- insertion sort(插入排序)
- 解决:ERROR: Cannot launch Jack server
- velocity模板引擎学习(1)
- JS-DOM对象知识点汇总(慕课)
- CCF第四题无向图打印路径
- Win10 开发者模式开启
- 用 eric6 与 PyQt5 实现python的极速GUI编程(系列03)---- Drawing(绘图)(2)-- 画点
- 查看nginx版本号
- Android笔记:真机调试
- C++:FMC 错误
- 你好,C++(29)脚踏两只船的函数不是好函数 5.4 函数设计的基本规则
- 深入理解7816(4)---关于T=1
- python-md5加密
- mybatis generator 插件安装及使用
- mysql 报错 session halted的解决办法,实际工作中的结论。
- SQLServer2008数据库连接error40错误
- GIT工程迁移方法总结
- 例10-10 uva10491(简单概率)
热门文章
- Django1.6 +wsgi 部署到Apache2 的步骤。
- cannot be translated into a null value due to being declared as a primitive type. Consid
- 下一个时代,对话即平台 —— 开始使用Bot Framework和Cognitive Service来打造你的智能对话服务
- Splash 笔记
- CI框架中 日志输出方法log_message()只允许输出字符串解决方案
- GAN网络
- Enterprise Architect UML建模
- 【BZOJ】2015: [Usaco2010 Feb]Chocolate Giving(spfa)
- VS2008 调试出现错误 ";Unable to start debugging.";
- js和jquery获取父级元素、子级元素、兄弟元素的方法{转}