I have a Python server and a java client. when a string is sent from java to python, it's not complete. Example:
Java Code Sending: Helloooooooooo
Recieved in Python as:
he
lloooooooo
oo
here are the codes
Python server:
import socket
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server_address = ("localhost", 10000)
print 'starting up on %s port %s' % server_address
sock.bind(server_address)
sock.listen(5)
while True:
print 'waiting for a connection'
connection, client_address = sock.accept()
try:
print 'connection from', client_address
while True:
data = connection.recv(1024)
print 'received: ' + data
print type(data)
if data:
print 'sending data back to the client'
connection.sendall(data)
else:
print 'no more data from', client_address
break
finally:
connection.close()
Java Client:
package server;
import java.io.*;
import java.net.*;
class Reciever_test {
public static void main(String args[]) throws Exception {
String sentence;
String modifiedSentence;
BufferedReader inFromUser = new BufferedReader(new InputStreamReader(System.in));
Socket clientSocket = new Socket("localhost", 10000);
DataOutputStream outToServer = new DataOutputStream(clientSocket.getOutputStream());
BufferedReader inFromServer = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
while(true)
{
sentence = inFromUser.readLine();
outToServer.writeBytes(sentence + "\n");
modifiedSentence = inFromServer.readLine();
System.out.println("FROM SERVER:" + modifiedSentence);
}
//clientSocket.close();
}
}
\n
. – Klaus D.