Partage
  • Partager sur Facebook
  • Partager sur Twitter

java socket connects but don't send any text

    28 octobre 2019 à 18:33:05

    I'm using port fowarding to connect my java code to my python serveur but the  java code can only connect to hit, i think it might be cause, i try to do that my java code connects, send and receive a message from the serveur without closing it. So send to the serveur and after receive a message from the serveur. But after doing this modification now i can't send any message to it.I think the error his in java code but it might be in the python code. Thank to help me if you know the answer. 

     sock = new Socket( "public ip router", 1234);
    
    
                        printWriter = new PrintWriter( sock.getOutputStream(),true);
                        try {
                            printWriter.write( "hello world" );
                            printWriter.flush();
                        }catch (Exception e){
                            System.out.println( e );
                        }
                        dis = new DataInputStream(sock.getInputStream());
                        final String message_entrant21;
    
                        message_entrant21 = dis.readLine();
                        Message232 = message_entrant21;
                        printWriter.close();
                        sock.close();
    

    and the serveur in python

     try:
                host, port = ('',1234)
                socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    
                o=False
                while o==False:
                    try:
                        socket.bind((host, port))
                        print("le serveur est démarré! o = true")
                        o=True
                    except OSError:
                        o=False
                    finally:
                        if(o is not False):
                            o=True
    
                socket.listen(5)
                conn, adress = socket.accept()
                print("listening")
                data2= conn.recv(255)
                print("send the message")
                socket.sendall("hello to you")
    
    




    -
    Edité par RaphaelScott 28 octobre 2019 à 18:35:39

    • Partager sur Facebook
    • Partager sur Twitter
      28 octobre 2019 à 19:50:30

      Bonjour,

      Mauvais forum

      Le sujet est déplacé de la section Langage Java vers la section Let's talk!

      • Partager sur Facebook
      • Partager sur Twitter

      java socket connects but don't send any text

      × Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
      × Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.
      • Editeur
      • Markdown