You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Which Wayland compositor or X11 Window manager(s) are you using?
No response
WezTerm version
0
Ask your question!
Previously, I had created a terminal server using nix::pty(it was working). The server has a few endpoints:
POST /terminals: This endpoint accepts rows and cols, creates a PTY, and stores its reader and writer along with a process ID.
WebSocket: This connects to the PTY using the process ID and facilitates data transmission in both directions.
Resize and Terminate: Endpoints for resizing and terminating the PTY.
However, when I ported the code to portable_pty, I encountered an issue with the WebSocket endpoint. When I connect to a PTY using a process ID, it sends the initial prompt data, but when I try to send a command (e.g., "pwd"), nothing happens. This behavior works correctly when the server runs on a PC (Linux desktop), but when compiled and run on Android (using Termux terminal emulator), it gets stuck — as described above.
What’s the problem? I suspect it’s related to resource limitations, but I’m not entirely sure.
I want to get output from pty when sending something, as on frontend I have connected using websocket to xtermjs library
Any help would be appreciated!
Note
I'm using latest axum web framework and portable pty from latest commit
My websocket endpoint code :
structTerminalSession{master:Arc<Mutex<Box<dynMasterPty + Send>>>,reader:Arc<Mutex<Box<dynRead + Send>>>,writer:Arc<Mutex<Box<dynWrite + Send>>>,}asyncfnhandle_socket(socket:WebSocket,pid:u32,sessions:Sessions){let(sender,mut receiver) = socket.split();let session_lock = sessions.lock().await;ifletSome(session) = session_lock.get(&pid){
tracing::info!("WebSocket connection established for terminal {}", pid);let reader = session.reader.clone();let writer = session.writer.clone();drop(session_lock);let ws_sender = Arc::new(Mutex::new(sender));let ws_sender_clone = ws_sender.clone();
tokio::spawn(asyncmove{letmut buffer = [0u8;4096];loop{let n = {letmut reader = reader.lock().await;match reader.read(&mut buffer){Ok(n)if n > 0 => n,
_ => break,}};ifletOk(text) = String::from_utf8(buffer[..n].to_vec()){ifletErr(_) = ws_sender_clone
.lock().await.send(Message::Text(text)).await{
tracing::error!("Failed to send WebSocket message for terminal {}", pid);break;}}}});whileletSome(Ok(message)) = receiver.next().await{
tracing::debug!("Received message from WebSocket: {:?}", message);match message {Message::Text(text) => {letmut writer = writer.lock().await;let processed_text = if text == "\r"{"\r\n".to_string()}else{
text
};if writer.write_all(processed_text.as_bytes()).is_err(){
tracing::error!("Failed to write to terminal {}", pid);break;}if writer.flush().is_err(){
tracing::error!("Failed to flush terminal {}", pid);break;}}Message::Binary(data) => {letmut writer = writer.lock().await;if writer.write_all(&data).is_err(){
tracing::error!("Failed to write binary data to terminal {}", pid);break;}if writer.flush().is_err(){
tracing::error!("Failed to flush terminal {}", pid);break;}}
_ => {}}}}}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
What Operating System(s) are you running on?
Linux Wayland
Which Wayland compositor or X11 Window manager(s) are you using?
No response
WezTerm version
0
Ask your question!
Previously, I had created a terminal server using
nix::pty
(it was working). The server has a few endpoints:/terminals
: This endpoint acceptsrows
andcols
, creates a PTY, and stores its reader and writer along with a process ID.However, when I ported the code to
portable_pty
, I encountered an issue with the WebSocket endpoint. When I connect to a PTY using a process ID, it sends the initial prompt data, but when I try to send a command (e.g.,"pwd"
), nothing happens. This behavior works correctly when the server runs on a PC (Linux desktop), but when compiled and run on Android (using Termux terminal emulator), it gets stuck — as described above.What’s the problem? I suspect it’s related to resource limitations, but I’m not entirely sure.
I want to get output from pty when sending something, as on frontend I have connected using websocket to xtermjs library
Any help would be appreciated!
Note
I'm using latest axum web framework and portable pty from latest commit
My websocket endpoint code :
Beta Was this translation helpful? Give feedback.
All reactions