Windows real-time access to Ubuntu server pictures [Elementary]

Windows real-time access to Ubuntu server pictures [Elementary]

Foreword:

This method is too inelegant. If you have any other ways, you must let me know~

Previously, due to mujoco rendering problems, only the remote control software could be used, and the program must be started on the desktop.
Now in the new version, it is finally possible to render pictures offline.
But with remote IDEs such as VSCODE and pycharm, it is not possible to call pygame and other real-time rendering;
but sometimes we need to watch some pictures generated by the current simulation environment in real time,
so I wonder if it can be built A channel to realize the transfer of pictures and other files. After all, we have a stable LAN communication;
the plan designed at nine in the morning is a bit outrageous:

1.远程脚本产生图片,存入远程服务器本地;
2.远程脚本通过subprocess启动本地脚本;
3.本地脚本通过subprocess获取服务器图片;
4.本地脚本通过pygame渲染图片;

This critical step was ignored by me. How to get the server's image in the local script?
That still has to communicate via ssh;
this communication time cannot be ignored.

Secondly, I have been unable to remotely call python scripts under Windows in Ubuntu.
At most, you can log in to Windows with SSH, but all the following commands cannot be executed correctly, various errors are reported, and the answer is not found, this way is abandoned.

In the end, I chose SCP to transfer files

In the end, I chose scp to transfer files. This instruction is very simple, and it was often used on the command line before.
But there are two points to note:

Genuine Windows 10 install ssh server

  1. You need to install ssh server under your Windows:
    If everything is normal on your Windows 10, then you can install it directly in this tutorial:
    Add ssh service under win10

Other installation freeSSHD

  1. If your Windows is db, there will be such an error:
    Error: 0x80070424
  2. At this time, you need to install freesshd
    into download, download freeSSHd.exe, and install it to any location;
  3. Set user, login to define your account name;
  4. Choose Password stored as SHA1 hash and set your password;
  5. user can shell, sftp, tunneling,都选上;
  6. Set up ssh, select listen address, select your IP address. Nothing else;
  7. At this time, you can set up Windows as a server similar to Ubuntu.
  8. To set the home path in SFTP, after setting it, the file transfer will be in the current directory.

If the ssh server cannot be started, an error is reported that the Permission is not enough:

Permission denied, please try again when using ssh to log in remotely.

Just 此电脑click under Windows , then click 管理, then 服务与应用程序, then 服务, and then find freeSSHDserver, and restart this service.
At this time, you can click on run ssh server:

Insert picture description here

Test ssh connection to Windows on Ubuntu:

Similar to controlling Ubuntu, directly:

ssh youruser@192.168.23.23

It's almost enough to enter the password.

sshpass eliminates the need to enter a password separately

Of course, in order to avoid entering the password every time, you can install the following packages under Ubuntu:sshpass

sudo apt-get install sshpass

After that, the remote command will be in the following format:

sshpass -p 'your password' ssh user@192.168.23.23

scp transfer files to windows in python script

When the channel is opened, the file can be transferred to Windows through scp. At this time, we regard Ubuntu as the client and Windows as the server, so we upload the file to the Windows server.
The tutorial for uploading files in the command line is as follows:
Remote copy between scp servers
The command line without password input is as follows:

sshpass -p 'your password' scp -r ssh_img.jpg lyl@192.168.23.23:

There is a very weird problem here, I can’t understand, and I can’t find a bug in the solution, that is, the uploaded folder can only be the C drive, and it cannot be switched to another drive. Even if you write the path of the other drive, you will not report an error. , Will create an empty file in the initial directory of the C drive.
Or just report an error:

scp: Failed to open file /d:/.
lost connection

I realized that this problem may only occur in freesshd, so I took a look.
Sure enough, I found the reason: I had to set up the home directory for file transfer in SFTP. After I set it up, I wrote something messy after the IP address.
Insert picture description here

Execute the command line statement in the python script:

import os
sync_cmd = "sshpass -p 'your password' scp -r ssh_img.jpg [email protected]:"
# 下面是将字符串在命令行中执行的意思
os.system(sync_cmd)

Basically one picture in 0.3 seconds, directly in the folder under Windows, you can directly see the picture refresh;

Effect picture

Insert picture description here

to sum up:

This method is too inelegant, although it barely works.
If you have any other good methods, be sure to point the way~

contact details:

ps: Welcome students who are intensive to join the group to study together:

Deep Reinforcement Learning-DRL: 799378128

Welcome to follow Zhihu account: Alchemy apprentices who have not yet started

CSDN account: https://blog.csdn.net/hehedadaq

Minimal spinup+HER+PER code implementation: https://github.com/kaixindelele/DRLib

Guess you like

Origin blog.csdn.net/hehedadaq/article/details/115049461