I have code written in Java, as I don't know java wanted to establish a socket connection using python but I'm unable to understand what is python equivalent of Java getInputStream() and getOutputStream() ? And how can we use it in python ? Following, you can find the code I already wrote in python.
import socket
try:
resMsg = None
myClient = None
myClient = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
ip = socket.gethostbyname("usddcwvtrkjxts3")
#print(ip)
port = 3450
address = (ip, port)
myClient.connect(address)
data = myClient.recv(1024)
print(data)
except:
print("connection failed")
I have following code already written in Java:
public String invoke(String requestMsg) {
String resMsg = null;
Socket myClient = null;
DataInputStream input = null;
PrintWriter output = null;
try {
try {
myClient = new Socket("vwddtrkjxts002", 3450);
input = new DataInputStream(myClient.getInputStream());
output = new java.io.PrintWriter(myClient.getOutputStream(), true);
output.println(requestMsg);
output.write("\u001A");
output.flush();
StringBuffer message = new StringBuffer();
try {
while (true) {
message.append((char) input.readByte());
}
} catch (EOFException e1) {
}
resMsg = message.toString();
System.out.println(resMsg);
} catch (UnknownHostException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
output.close();
input.close();
myClient.close();
} catch (IOException e) {
System.out.println(e);
}
}
return resMsg;
}
I'm able to establish a connection with python but unable to print anything as output.
Any suggestion will help ! Thank you in advance

send()orsendall(). To receive data from the peer userecv().