Skip to main content

Decode The String Received From Java Socket And Encode The String for Send To The Java Socket. Connect Python And Java Sockets

Project description

Decode The String Received From Java Socket And Encode The String for Send To The Java Socket

Connect Python And Java Sockets

Send And Recieveing The Data Beetween Java And Python Sockets.

Installation :
pip install jpysocket

Remove Package :
pip uninstall jpysocket

Import Library :
import jpysocket

Connect Python Server And Java Client.
Connect Python Client And Java Server.
Send Python Socket Massage To Java Socket.
Recieve Massage From Java Socket in Python Sockete.


The Followings Are The Some Example Of jpysocket Librery


Python Server :

import jpysocket
import socket

host='localhost' #Host Name
port=12345    #Port Number
s=socket.socket() #Create Socket
s.bind((host,port)) #Bind Port And Host
s.listen(5) #Socket is Listening
print("Socket Is Listening....")
connection,address=s.accept() #Accept the Connection
print("Connected To ",address)
msgsend=jpysocket.jpyencode("Thank You For Connecting.") #Encript The Msg
connection.send(msgsend) #Send Msg
msgrecv=connection.recv(1024) #Recieve msg
msgrecv=jpysocket.jpydecode(msgrecv) #Decript msg
print("From Client: ",msgrecv)
s.close() #Close connection
print("Connection Closed.")

Java Client :

Client.java

 import java.io.*;  
  import java.net.*; 
  public class Client {
  public static void main(String[] args) {  
  try{      
  Socket soc=new Socket("localhost",12345);  
  DataOutputStream dout=new DataOutputStream(soc.getOutputStream());  
  DataInputStream in = new DataInputStream(soc.getInputStream());
  String msg=(String)in.readUTF();
  System.out.println("Server: "+msg);
  dout.writeUTF("Ok Boss");
  dout.flush();
  dout.close();
  soc.close();
  }
  catch(Exception e)
  {
      e.printStackTrace(); 
  }}}  

Python Client :

import jpysocket
import socket

host='localhost' #Host Name
port=12345    #Port Number
s=socket.socket() #Create Socket
s.connect((host,port)) #Connect to socket
print("Socket Is Connected....")
msgrecv=s.recv(1024) #Recieve msg
msgrecv=jpysocket.jpydecode(msgrecv) #Decript msg
print("From Server: ",msgrecv)
msgsend=jpysocket.jpyencode("Ok Boss.") #Encript The Msg
s.send(msgsend) #Send Msg
s.close() #Close connection
print("Connection Closed.")

Java Server :

Server.java

import java.io.*;  
import java.net.*; 
public class Server {
  public static void main(String[] args) {
      try{ 
      ServerSocket serverSocket = new ServerSocket(12345);
      Socket soc = serverSocket.accept();
      System.out.println("Receive new connection: " + soc.getInetAddress());
      DataOutputStream dout=new DataOutputStream(soc.getOutputStream());  
      DataInputStream in = new DataInputStream(soc.getInputStream());
      dout.writeUTF("Thank You For Connecting.");
      String msg=(String)in.readUTF();
      System.out.println("Client: "+msg);
      dout.flush();
      dout.close();
      soc.close();
      }
      catch(Exception e)
      {
      e.printStackTrace(); 
  }
  }
  }

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

jpysocket-1.1.5-py3-none-any.whl (3.3 kB view details)

Uploaded Python 3

File details

Details for the file jpysocket-1.1.5-py3-none-any.whl.

File metadata

  • Download URL: jpysocket-1.1.5-py3-none-any.whl
  • Upload date:
  • Size: 3.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.0

File hashes

Hashes for jpysocket-1.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 dde7ff55b6efc8fdcdd29b9ef35d612c54a1d1431e159be5bf45eb6bdfe6469a
MD5 d656023098d45fb353dfef522bfbf4a6
BLAKE2b-256 08aab234b2f21e63858ae5ada92f4157e36c55c3751909c885a58d220e83396d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page