[share] Batch local multi-process communication and LAN communication, no third party, no temporary files

Microsoft Windows
Post Reply
Blitz
Posts: 2
Joined: 2021-Oct-09, 9:28 pm

[share] Batch local multi-process communication and LAN communication, no third party, no temporary files

Post by Blitz »

There are still many shortcomings. If both parties send content at the same time, there will be bugs. When writing, it is written on one computer, so the reading part of the two computers will also shift with the writing part.
Cannot delete the previous line, case is not handled

send.bat

Code: Select all

@echo off
for /f %%a in ('echo prompt $H^|cmd') do set "bs=%%a"
title 发送
:1
set "key="
for /f "delims=" %%a in ('xcopy /w . 2^>nul') do if not defined key set "key=%%a"
set key=%key:~-1%
if "%key%" == "" (
    echo=
    set key=enter
) else if "%key%" == "%bs%" (
    <nul set/p=%bs% %bs%
    set key=backspace
) else if "%key%" == " " (
    <nul set/p=_%bs% 
    set key=space
) else <nul set/p=%key%
>nul waitfor /si %key%
goto 1
receive.bat

Code: Select all

@echo off
for /f %%a in ('echo prompt $H^|cmd') do set "bs=%%a"
title 接收
if not "%1" == "" goto a
for %%a in (0 1 2 3 4 5 6 7 8 9 a b c d e f g h i j k l m n o p q r s t u v w x y z enter backspace space) do start /b "" "%~f0" %%a
pause>nul
exit

:a
>nul waitfor %1
if "%1" == "enter" (
    echo=
) else if "%1" == "backspace" (
    <nul set/p=%bs% %bs%
) else if "%1" == "space" (
    <nul set/p=_%bs% 
) else <nul set/p=%1
goto a
write in a window

Code: Select all

@echo off
title demo
mode 60,40
set r_h=3
set r_l=15
set response_w=22;15

for /f %%a in ('echo prompt $H^|cmd') do set "bs=%%a"
for /f %%a in ('echo=prompt $E^|cmd') do set "esc=%%a"


if not "%1" == "" goto a
echo=加载中....
for %%a in (0 1 2 3 4 5 6 7 8 9 a b c d e f g h i j k l m n o p q r s t u v w x y z enter backspace space) do start /b "" "%~f0" %%a&&ping 127.1 /n 1 >nul
cls
ping 127.1 /n 2 >nul
set/pa=%esc%[20;1H<nul
echo=============================================================
set/pa=%esc%[%r_h%;%r_l%H<nul
:1
set "key="
for /f "delims=" %%a in ('xcopy /w . 2^>nul') do if not defined key set "key=%%a"
set key=%key:~-1%
if "%key%" == "" set key=enter
if "%key%" == "%bs%" set key=backspace
if "%key%" == " " set key=space
call :draw %key%
>nul waitfor /si %key% /s 192.168.1.7
goto 1



:a
>nul waitfor %1
if "%1" == "enter" (
    echo=
    <nul set/p=_%bs%              
) else if "%1" == "backspace" (
    <nul set/p=%bs% %bs%
) else if "%1" == "space" (
    <nul set/p=_%bs% 
) else (
    <nul set/p=%1
)
goto a


:draw
if "%1" == "enter" (
    set/pa=%esc%[%response_w%H<nul
    echo=
    <nul set/p=_%bs%              
    call :get_cursor_pos pos response_w
    set/ar_h+=1
    set r_l=15
    set/pa=%esc%[%r_h%;%r_l%H<nul
) else if "%1" == "backspace" (
    set/pa=%esc%[%response_w%H<nul
    <nul set/p=%bs% %bs%
    call :get_cursor_pos pos response_w
    set/ar_l-=1
    set/pa=%esc%[%r_h%;%r_l%H<nul
) else if "%1" == "space" (
    set/pa=%esc%[%response_w%H<nul
    <nul set/p=_%bs% 
    call :get_cursor_pos pos response_w
    set/ar_l+=1
    set/pa=%esc%[%r_h%;%r_l%H<nul
) else (
    set/pa=%esc%[%response_w%H<nul
    <nul set/p=%1
    call :get_cursor_pos pos response_w
    set/ar_l+=1
    set/pa=%esc%[%r_h%;%r_l%H<nul
)
exit /b


:get_cursor_pos
set "response="
set pos=2
:_get_loop
<nul set /p "=%esc%[6n" 
for /l %%# in (1 1 %pos%) do pause<con>nul
set "char=;"
for /f "tokens=1 skip=1 delims=*" %%c in ('"replace /w ? . < con"') do set "char=%%c"
set "response=%response%%char%"
set /a pos+=1
if "%char%" neq "R" goto :_get_loop
set %2=%response:~0,-1%
exit /b
Post Reply