• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Jj Roberts
  • Al Hobbs
  • Piet Souris

communication between a java client and a python server using TLS

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am new to python and TLS socket programming domain. I have to make a java client and a python server exchange messages using TLS.
when I try to send something from the server to the client I either receive nothing when I use BufferedReader in java or I receive "null" when I use inputStream I don't receive anything and when I ask an input from the python server side to send it to the client I get this error " TypeError: memoryview: a bytes-like object is required, not 'str'"
I really don't know how to solve this problem especially that I don't know much about SSL or encoding.

this is my server.py:

this is client.java


 
Marshal
Posts: 3708
523
Android Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Maybe start with something simple on both sides and incrementally build-out the complexity to meet your end goal.

As a starting point on the Java side, you could do something like this:

It will establish a connection, and then go in to a loop of: reading a byte from the input stream, printing it on the console, and writing it to the output stream to echo it back to the server.

Not that it matters functionally, but I would recommend using a port other than 80.  Port TCP 80 is normally used for unencrypted HTTP traffic, and since it is below 1024, it is consider a privileged port and should be used by system services, not user applications.

 
ines elmufti
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I tried it, however it never goes out of the while loop and only sends back the first char
 
Ron McLeod
Marshal
Posts: 3708
523
Android Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

ines elmufti wrote:I tried it, however it never goes out of the while loop and only sends back the first char


I don't know why is would not working with more than one character (I just tried the same code and it does work for me), but staying in the loop until the socket is closed by the server-end is what the code does.  It is not where you want to end-up, but it does help prove that you have basic interoperability between the client and server: connectivity path and crypto both working.

The next step would be to define the application protocol that you will carry over this secure communications channel.  If the payloads that you will be exchanging don't have a fixed length, then you will need to have some kind of mechanism in-place for that the receiving end to know when it has completely received what the sending side transmitted such as:
   - prepending a length indicator on the data your sending - for example to send Hello: 05 48 65 6c 6c 6f
      or
   - flagging the end of data with a byte which would not be used - for example: 48 65 6c 6c 6f 00
 
Master Rancher
Posts: 180
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is this topic related?
https://coderanch.com/t/739044/java/Socket-Programming-Java-TLS
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic