I am trying to send a string encoded in utf to a server and get a response from it.However I am not able to get any response as i think the string I'm sending from the client has not been encoded properly. Here is what I've done to encode the string:
a= "!@#$%"
u = a.encode('utf-8')
s=socket.socket()
s.connect((ipAddr,portNum))
a=s.recv(1024)
print (a)//prints ok
s.send(u)
s.recv(1024)#blank
print (s.recv(1024))
JAVA:
Socket smtpSocket = new Socket(ipAddr,portNum);
smtpSocket.setSoTimeout(1000*30);
is = new BufferedReader(new InputStreamReader(smtpSocket.getInputStream()));
service=new DataOutputStream(smtpSocket.getOutputStream());
String response = is.readLine();
System.out.println(response);
if(response.startsWith("okE"))
{
service.writeUTF(x);
}
response = is.readLine();
System.out.println(response);