Python Forum
Need some help with networking problems...
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Need some help with networking problems...
#1
so im trying to make a server that can communicate with the client, this is my code
server:
#!/usr/bin/python3           # This is server.py file
import socket                                         

# create a socket object
serversocket = socket.socket(
	        socket.AF_INET, socket.SOCK_STREAM) 

# get local machine name
host = socket.gethostname()                           

port = 9996                                         

# bind to the port
serversocket.bind((host, port))                                  

# queue up to 5 requests
serversocket.listen(5)                                           

while True:
   # establish a connection
   clientsocket, addr = serversocket.accept()      
   msg = input("what do you want to send?\n")
   clientsocket.send(msg.encode('ascii'))
   
client:
#!/usr/bin/python3 # This is client.py file 
import socket # create a socket object 

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) # get local machine name

host = socket.gethostname() 
port = 9996 # connection to hostname on the port. 

s.connect((host, port)) # Receive no more than 1024 bytes 
but the problem is i can send one message, and then it wont send more?
why?
help?
Reply
#2
I do not see the client sending any message.
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply
#3
(Oct-17-2018, 02:44 PM)wavic Wrote: I do not see the client sending any message.
yeah but its the server thats suppose to send a message to the client, an custom message, allmost like a masseging app
Reply
#4
Well, how the client receives the message?
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply
#5
(Oct-17-2018, 03:05 PM)wavic Wrote: Well, how the client receives the message?
it recieves it, and then if i send ANOTHER message it wont send it? or it will send but the client wont receiv it?
HEEEELP
Reply
#6
The client closes and that closes the connection. Put a while loop in the client.
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply
#7
As your code is written, the client program exits after sending the first message, which closes the socket connection. The server complains about that. If you want to be able to send multiple messages from the client, you'll need a looping or event structure on both the client and server side.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How can I begin learning networking? rohit19 5 3,921 Feb-10-2021, 09:56 AM
Last Post: Naheed
  Networking Help iMuny 1 2,044 Apr-13-2020, 05:37 PM
Last Post: Larz60+
  Networking archer491 0 2,009 Dec-11-2019, 10:17 AM
Last Post: archer491
  COMPLETE BEGINNER TO NETWORKING. HELP? ShadowWarrior17 11 7,617 Jan-06-2018, 02:05 PM
Last Post: sparkz_alot
  Python 2 http networking problems, if any Aeneas 1 3,114 Sep-06-2017, 07:24 PM
Last Post: wavic

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020