package top.duanhong.emims.controller.rest.remote;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
/**
* socket服务
* @author Administrator
*/
public class Gprs{
//private static List<Socket> clients = new LinkedList<Socket>();
/**
*
*/
private static Map<String, Socket> clients=new LinkedHashMap<String, Socket>();
static PrintWriter pw = null;
static FileWriter fw = null;
public static void main(String[] args) {
int port = 10001;
try {
ServerSocket server = new ServerSocket(port);
while (true) {
// 获得客户端连接
// 阻塞式方法
System.out.println("准备阻塞...");
final Socket client = server.accept();
System.out.println("阻塞完成...");
new Thread(new Runnable() {
@Override
public void run() {
try {
InputStream is = client.getInputStream();
//获取输出流 给客服的写数据
OutputStream os = client.getOutputStream();
byte[] buffer = new byte[1024];
int len = -1;
System.out.println("准备read...");
while ((len = is.read(buffer)) != -1) {
String text=new String(buffer,0,len);
System.out.println(text);
System.out.println("read完成...");
if(text.startsWith("#"))
{
clients.put(text, client);
os.write("认证成功".getBytes());
}else{
os.write("收到了你的请求".getBytes());
// String[] split = text.split(":");
// String key="#"+split[0];
// String content=split[1];
// 关联文件
File file = new File("c:\\123.txt");
if(!file.exists()){
// 判断文件不存在就new新文件,写数据
try {
file.createNewFile();
// java IO流和文件关联
pw = new PrintWriter(file);
pw.print(text + "\t");
pw.println();
pw.flush();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}else{
// 判断文件存在,就以FileWriter文件追加的方式写文件
try {
fw = new FileWriter("c:\\123.txt",true);
fw.write(text + "\r\n");
fw.flush();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
// Socket s = clients.get(key);
// if(s!=null){
// OutputStream output = s.getOutputStream();
// output.write(content.getBytes());
// }
}
}
}
catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}).start();
}
}
catch (Exception e) {
e.printStackTrace();
}
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
stm32环境监测服务系统.zip
共501个文件
gif:150个
java:92个
js:82个
需积分: 0 0 下载量 41 浏览量
2023-08-11
20:09:50
上传
评论
收藏 3.48MB ZIP 举报
温馨提示
stm32环境监测服务系统.zip
资源推荐
资源详情
资源评论
收起资源包目录
stm32环境监测服务系统.zip (501个子文件)
mvnw.cmd 6KB
bootstrap.css 124KB
layui.css 87KB
layui.css 71KB
font-awesome.css 37KB
font-awesome.min.css 30KB
admin.css 25KB
font-awesome.css 23KB
bootstrap-responsive.css 22KB
elements.css 20KB
jquery-ui-1.10.2.custom.css 19KB
elements.css 19KB
wangEditor.css 17KB
select2.css 17KB
wangEditor.min.css 15KB
layer.css 14KB
layer.css 14KB
layout.css 12KB
fullcalendar.css 11KB
layuimini.css 11KB
uniform.default.css 11KB
bootstrap.datepicker.css 10KB
layui.mobile.css 10KB
layui.mobile.css 10KB
bootstrap-overrides.css 9KB
zyupload-1.0.0.min.css 9KB
laydate.css 7KB
laydate.css 7KB
index.css 6KB
gallery.css 4KB
signup.css 4KB
signin.css 4KB
tables.css 4KB
user-profile.css 3KB
ui-elements.css 3KB
form-wizard.css 3KB
new-user.css 3KB
personal-info.css 3KB
icons.css 2KB
calendar.css 2KB
form-showcase.css 2KB
user-list.css 2KB
step.css 1KB
code.css 1KB
code.css 1KB
bootstrap-wysihtml5.css 1KB
public.css 676B
fullcalendar.print.css 668B
web-app-icons.css 504B
commonStyle.css 499B
chart-showcase.css 474B
morris.css 443B
grids.css 366B
treetable.css 294B
code-editor.css 209B
emims_style.css 57B
fontawesome-webfont.eot 162KB
iconfont.eot 41KB
iconfont.eot 40KB
fontawesome-webfont_2d2816fe.eot 29KB
fontawesome-webfont_51500cb8.eot 29KB
59.gif 10KB
59.gif 10KB
22.gif 10KB
22.gif 10KB
24.gif 8KB
24.gif 8KB
13.gif 7KB
13.gif 7KB
16.gif 7KB
16.gif 7KB
39.gif 6KB
39.gif 6KB
64.gif 6KB
64.gif 6KB
63.gif 6KB
63.gif 6KB
50.gif 6KB
50.gif 6KB
loading-0.gif 6KB
loading-0.gif 6KB
4.gif 6KB
4.gif 6KB
1.gif 5KB
1.gif 5KB
42.gif 5KB
42.gif 5KB
71.gif 5KB
71.gif 5KB
21.gif 5KB
21.gif 5KB
20.gif 5KB
20.gif 5KB
29.gif 5KB
29.gif 5KB
70.gif 4KB
70.gif 4KB
5.gif 4KB
5.gif 4KB
17.gif 4KB
共 501 条
- 1
- 2
- 3
- 4
- 5
- 6
资源评论
程皮
- 粉丝: 261
- 资源: 2568
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功