Navigation

    ask avan logo
    • Register
    • Login
    • Search
    • Categories
    • Unsolved
    • Solved

    I am learning socket python but keep getting error in my client file. Please help.

    Python
    2
    3
    15
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • anushree bajaj
      anushree bajaj last edited by avan

      Client.py

      import socket
      headersize = 10
      c = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
      c.connect((socket.gethostname(),9999))
      
      while True:
              full_msg= ""
              new_msg = True
              while True:
                      msg = c.recv(15)
                      if new_msg :
                              msglen = int(msg[:headersize])
                              new_msg = False   
                      full_msg += msg.decode("utf-8")
                      if len(full_msg)-headersize == msglen:
                                      print("full msg recvd, Length = ", msglen)
                                      print(full_msg[headersize:])
                                      new_msg = True
                      
             
      

      it gives

      ValueError: invalid literal for int() with base 10: b''
      
      Reply Quote 0
        1 Reply Last reply

      • avan
        avan last edited by

        Did you provide us with all the information/code needed? Remember, more is better.

        Reply Quote 0
          1 Reply Last reply

        • avan
          avan last edited by

          @anushree-bajaj said in I am learning socket python but keep getting error in my client file. Please help.:

          msglen = int(msg[:headersize])

          Have you tried googling the exact error message?

          e.g.

          ValueError: invalid literal for int() with base 10: b''
          

          When I tried googling it I got the following answer:

          https://stackoverflow.com/questions/1841565/valueerror-invalid-literal-for-int-with-base-10

          So try changing

           msglen = int(msg[:headersize])
          

          to

           msglen = float(msg[:headersize])
          

          I am not a python guy so not sure how that will affect your program. Let me know . ☺

          Reply Quote 0
            1 Reply Last reply

          • First post
            Last post