原本的kotlin代码
val socket = Socket(host, port)
Log.d("MainActivity", "Connected to $host:$port")
// 获取输出流,用于向服务器发送数据
val outputStream = socket.getOutputStream()
val printWriter = PrintWriter(outputStream, true) // 自动刷新
// 发送数据到服务器
printWriter.println(message)
Log.d("MainActivity", "Sent message: $message")
// (可选)读取服务器响应(如果需要)
val inputStream = socket.getInputStream()
val reader = BufferedReader(InputStreamReader(inputStream))
val serverResponse = reader.readLine()
Log.d("MainActivity", "Server response: $serverResponse")
// 关闭Socket连接
socket.close()
const socket = new Socket("172.25.3.1", 3160)
// 获取输出流,用于向服务器发送数据
const outputStream = socket.getOutputStream()
let printWriter =new PrintWriter(outputStream, true)
printWriter.println("parameter 208888_28\n {'storeID':'208888','tableName':'store','paraName':null}")
let inputStream = socket.getInputStream()
let reader = new BufferedReader(
new InputStreamReader(inputStream)
)
let serverResponse = reader.readLine()
socket.close()
结果在报错:类型 'InputStreamReader' 无法赋值给类型 'Reader'。有名类型只能赋值给同名的有名类型。
new BufferedReader(
new InputStreamReader(inputStream)
)
根据我的经验,kotlin那边会去翻继承类,翻到有对应的,而UTS这边就会显示对不上。
尘雨雾录 (作者)
已更新回复
2024-07-29 09:38