简体   繁体   English

在客户端服务器游戏中通过网络发送文件

[英]Sending file over network in a client server game

  1. Does a file-class only keeps the link/path to a file or a copy of that in the memory ? 文件类是否仅将链接或路径或文件的副本/链接保留在内存中? I ask that in case of transfering a "File" object through network - is the path of the file transfered or the file too ? 我要求在通过网络传输“文件”对象的情况下-文件的路径还是文件传输的路径?

  2. Client-server communication (for a simple network game) 客户端-服务器通信(用于简单的网络游戏)

Story : i will have several clients wich are frequently need a information or file transfer with a Server in unknown order and number. 故事 :我将有几个客户端,它们经常需要与服务器以未知顺序和编号进行信息或文件传输。 The server also should send in a unknown order informations/files to the clients. 服务器还应以未知顺序向客户端发送信息/文件。 The server treated connections in making threads wich handle them. 服务器通过使连接处理线程来处理连接。

Questions : What is the recommended approach to handle those situations? 问题 :处理这些情况的推荐方法是什么?

I dont know if it is better to close the connection and thread every time the informations/file transfere is over and open a new one or to hold a thread and the socket connection for more. 我不知道每次信息/文件传输结束后关闭连接和线程是否更好,然后再打开一个新的线程还是保持线程和套接字连接的更多时间,是否更好。

  1. Linked with the question above - does the client use threads for incoming information/file transfers of the server too? 与上面的问题相关联-客户端是否也使用线程进行服务器的传入信息/文件传输?

  2. Is there a recommended way how i identify and store/handle the client connections, lost connections , reconnections. 有没有推荐的方式来标识和存储/处理客户端连接,丢失的连接,重新连接。

I would be pleased if you could give me some hints. 如果您能给我一些提示,我将很高兴。

Best wishes Mathias 最好的祝福Mathias

In Java, File is just an abstraction to a file system path (file or directory); 在Java中, File只是文件系统路径(文件或目录)的抽象; it does not contain the file contents. 它不包含文件内容。

In a client/server set up where you need to send a file over the network, you will need to use Java's IO constructs for that. 在需要通过网络发送文件的客户端/服务器设置中,您将需要使用Java的IO构造。 Exactly how will depend on how you intend communication to be done (HTTP, Sockets, RMI). 确切的方式将取决于您打算如何进行通信(HTTP,套接字,RMI)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM