Luasocket 服务器,客户端简单实例

server.lua

socket = require("socket");
host = host or "127.0.0.1";
port = port or "8383";
server = assert(socket.bind(host, port));
ack = "ack\n";
while 1 do
    print("server: waiting for client connection...");
    control = assert(server:accept());
    while 1 do 
        command,status = control:receive();
  if status == "closed" then break end
        print(command);
        control:send(ack);
    end
end

 

client.lua

local socket = require("socket")

host = "127.0.0.1"
port = 8383

--打开一个TCP连接
c = assert (socket.connect (host, port))

c:send ("GET \n")
while (true) do
 local s, status, partial = c:receive ()
 print(s)
 if status == "closed" then break end
 c:send ("GET \n")
end

c:close ()

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在Java中使用Minio客户端,你可以按照以下步骤进行操作: 1. 首先,在你的Java项目中添加Minio客户端的依赖。在你的项目的构建文件(例如pom.xml或build.gradle)中,添加以下依赖: Maven: ```xml <dependency> <groupId>io.minio</groupId> <artifactId>minio</artifactId> <version>7.1.0</version> </dependency> ``` Gradle: ```groovy implementation 'io.minio:minio:7.1.0' ``` 2. 在你的Java类中导入Minio客户端相关的类: ```java import io.minio.MinioClient; import io.minio.errors.MinioException; import io.minio.messages.Bucket; ``` 3. 创建一个MinioClient对象,并配置连接参数: ```java try { String endpoint = "your-minio-endpoint"; int port = your-minio-port; String accessKey = "your-access-key"; String secretKey = "your-secret-key"; MinioClient minioClient = new MinioClient(endpoint, port, accessKey, secretKey); // 接下来可以使用MinioClient对象进行操作 } catch (MinioException e) { System.out.println("Error occurred: " + e); } ``` 请根据你的Minio服务器配置替换上述代码中的连接参数。 4. 现在,你可以使用MinioClient对象执行各种操作,例如创建存储桶、上传文件等。以下是一个示例: ```java try { String bucketName = "your-bucket-name"; String objectName = "your-object-name.txt"; String filePath = "/path/to/your/file.txt"; // 创建存储桶(如果不存在) boolean isBucketExist = minioClient.bucketExists(bucketName); if (!isBucketExist) { minioClient.makeBucket(bucketName); System.out.println("存储桶创建成功!"); } // 上传文件 minioClient.putObject(bucketName, objectName, filePath, null); System.out.println("文件上传成功!"); } catch (MinioException e) { System.out.println("Error occurred: " + e); } ``` 请确保替换上述代码中的变量值,以适应你的具体需求。 这只是一个简单的示例,你可以根据Minio客户端的文档来了解更多可用的方法和操作。请确保你的Minio服务器配置正确,并且Java应用能够成功连接到Minio服务器

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值