如何让服务器和客户端访问相同的文件?

发布于 2025-02-13 03:58:54 字数 380 浏览 0 评论 0原文

我正在使用create-react-app,socket.io和打字稿制作多人游戏网络游戏。我能够启动服务器,并让玩家从服务器发送和接收信息。当服务器以外部文件启动时,播放器连接到React项目中的服务器。

但是,我现在需要服务器来访问React项目中的文件。例如,我在tile.ts文件中存储了一个瓷砖类,在React Project中,玩家可以访问,但服务器无法访问。我尝试了很多不同的事情,例如尝试在React项目中启动服务器,但是它们都没有成功,因为我想您无法从浏览器内部运行服务器。

目前,我看到的唯一解决方案是将文件从React项目复制到服务器所在的位置,然后在我想更改文件时更改文件的两个实例。

我的服务器有什么办法能够访问玩家可以访问的相同文件?另外,如果该帖子缺乏解释或细节,请告诉我。

I am making a multiplayer web game using create-react-app, socket.io and typescript. I am able to start a server and have players send and receive information from the server. The players connect to the server in a react project, while the server is started in an external file.

However, I now need the server to access files in the react project. E.g. I have a Tile class stored in the tile.ts file inside the react project which players are able to access, but the server cannot. I have tried a lot of different things such as attempting to start the server in the react project, but none of them have been successful as I suppose you cannot run servers from inside the browser.

Right now the only solution I can see is copying the files over from the react project into where the server is located, and then change both instances of the files whenever I want to change the file.

Is there any way for my server to be able to access the same files that the players can access? Also, if this post is lacking in explanation or detail, please tell me.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

山有枢 2025-02-20 03:58:56

由tile.ts从服务器生成的DOM的部分

如果要操纵 -demo-g3vst“ rel =” nofollow noreferrer“> https://codesandbox.io/s/reaect-iframe-demo-g3vst-iframe-demo-g3vst ) ,根据您的条件。将此API添加到IFRAME的SRC中。因此,每当DOM加载时,它将被渲染,并且根据条件也可以渲染。

if you want to manipulate the part of DOM which is getting generated by tile.ts from server then,

You can add iframe( https://codesandbox.io/s/react-iframe-demo-g3vst-iframe-demo-g3vst ) in tile.ts and then create an api in server which will serve the part which you want, based on your conditions. Add this api into src of iframe. So whenever the DOM will load it will be rendered and based on conditions also you can render.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文