Python Forum
Need some help with networking problems... - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Networking (https://python-forum.io/forum-12.html)
+--- Thread: Need some help with networking problems... (/thread-13485.html)



Need some help with networking problems... - GottaAimHigherPal - Oct-17-2018

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?


RE: Need some help with networking problems... - wavic - Oct-17-2018

I do not see the client sending any message.


RE: Need some help with networking problems... - GottaAimHigherPal - Oct-17-2018

(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


RE: Need some help with networking problems... - wavic - Oct-17-2018

Well, how the client receives the message?


RE: Need some help with networking problems... - GottaAimHigherPal - Oct-17-2018

(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


RE: Need some help with networking problems... - wavic - Oct-18-2018

The client closes and that closes the connection. Put a while loop in the client.


RE: Need some help with networking problems... - JunaithPetersen - Oct-18-2018

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.