在python中读/写java套接字

大家好,
我写信后,我从Java服务器上阅读有问题
向它 - 它只是悬挂.如果我只写入服务器,它可以正常工作
不尝试写.我已经阅读了插座上的howto - 它说明
有一个问题(关于冲洗的问题),但不是
解决方案是. Google也不是Google.有人可以帮忙吗?
下几行,您可以看到示例代码总结
问题.只需更改Python主机变量的名称即可.
谢谢
疯狂
这是Python中的客户:
#! /usr/bin/env Python
导入系统
从插座导入 *
端口= 3122
主机='app-5'
成功='成功'
失败='失败'
s =插座(af_inet,sock_stream)
s.connect((主机,端口))
S.Send(" Hi Java Server");
打印"书面,等待收到.."
PRINT S.RECV(1014)
s.close()
这是Java中的服务器:
导入java.io*;
导入Java.net.*;
公共类服务器{
公共静态void main(String args []){
int port = 3122;
int积压= 50;
serversocket ss = null;
尝试{
InetAddress localhost =
InetAddress.getLocalhost();
ss = new serversocket(端口,积压,
Localhost);
而(true){
最终插座客户端= ss.accept();
新线程(){
public void run(){
尝试{
InputStream IS =
client.getInputStream();
BufferedReader buf =
新的BufferedReader(new InputStreamReader(is));
打印(buf.readline());
printwriter out = new
printWriter(client.getOutputStream());
out.write("嗨Python)
客户.");
out.flush();
client.close();
}catch(Exception e)
{print(e);}
}
}.开始();
}
}catch(Exception e){print(e);}
}
private static void print(Object o){System.out.println(o);}
}

# 回答1


On Nov 27, 1:08 pm, madsornom...@gmail.com wrote:
I don't know, but it's amazing to compare the python client with the
java server.
# 回答2


On Nov 27, 4:29 pm, hdante [Snip - a little Python]
[Snip - a lot of Java]
I don't know, but it's amazing to compare the python client with the
Java服务器.

是的,Python真的很方便:)
/Mads

# 回答3


您的服务器程序正在使用ReadLine(),该程序将阻止直到
收到了新线.服务器代码不编写newline,因此
在recv()等待服务器的数据,服务器仍在
等待新线.如果您更改客户以执行以下操作,
应该管用:
S.Send(" Hi Java Server \ n");
戴夫
在文章中
,maxhyde*******@gmail.com写道:( _@_)

标签: python

添加新评论