我创建了python套接字服务器。我在一个请求中接受了 65536 个字节。
我使用 BufferedWriter 从Java套接字客户端发送 10000 字符串到python套接字服务器。
Python套接字服务器仅接受 5840 个字符。
Java BufferedWriter中是否有任何大小限制? python socket中有任何大小限制吗?
这里是我的python套接字服务器和Java套接字客户端程序代码。
Python套接字服务器
import socket
serversocket = socket.socket(
socket.AF_INET, socket.SOCK_STREAM)
host = socket.gethostname()
print (host)
port = 9999
serversocket.bind(("", port))
serversocket.listen(7)
print ("Server is listening client request....")
while True:
print ("It is true.....")
clientsocket,addr = serversocket.accept()
client_msg = clientsocket.recv(65536).decode()
print (len(client_msg))
print (client_msg)
Java套接字客户端
package test;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.net.Socket;
public class Tester {
public static void main(String[] args) {
String serverName = "192.168.1.99";
int port = 9999;
try {
String st = "";
for (int i = 0; i < 2000; i++) {
st = st + "Hello";
}
System.out.println(st.length());
Socket socket = new Socket(serverName, port);
OutputStream outstream = socket.getOutputStream();
OutputStreamWriter osw = new OutputStreamWriter(outstream);
BufferedWriter bw = new BufferedWriter(osw);
bw.write(st);
bw.flush();
bw.close();
osw.close();
outstream.close();
socket.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}