Indagamos en distintos sitios y así darte la solución para tu problema, en caso de dificultades puedes dejar tu pregunta y responderemos con mucho gusto, porque estamos para ayudarte.
Ejemplo 1: socket python del servidor cliente
#!/usr/bin/python # This is server.py file
import socket # Import socket module
s = socket.socket() # Create a socket object
host = socket.gethostname() # Get local machine name
port =12345 # Reserve a port for your service.s.bind((host, port)) # Bind to the port
s.listen(5) # Now wait for client connection.while True:
c, addr = s.accept() # Establish connection with client.
print 'Got connection from', addr
c.send('Thank you for connecting')
c.close() # Close the connection
Ejemplo 2: múltiples clientes en python de programación de sockets
import socket
ClientSocket = socket.socket()
host ='127.0.0.1'
port =1233print('Waiting for connection')try:
ClientSocket.connect((host, port))
except socket.error as e:print(str(e))
Response = ClientSocket.recv(1024)while True:
Input =input('Say Something: ')
ClientSocket.send(str.encode(Input))
Response = ClientSocket.recv(1024)print(Response.decode('utf-8'))
ClientSocket.close()
Ejemplo 3: múltiples clientes en python de programación de sockets
import socket
import os
from _thread import*
ServerSocket = socket.socket()
host ='127.0.0.1'
port =1233
ThreadCount =0try:ServerSocket.bind((host, port))
except socket.error as e:print(str(e))print('Waitiing for a Connection..')
ServerSocket.listen(5)
def threaded_client(connection):
connection.send(str.encode('Welcome to the Servern'))while True:
data = connection.recv(2048)
reply ='Server Says: '+ data.decode('utf-8')if not data:break
connection.sendall(str.encode(reply))
connection.close()while True:
Client, address = ServerSocket.accept()print('Connected to: '+ address[0]+':'+str(address[1]))start_new_thread(threaded_client,(Client,))
ThreadCount +=1print('Thread Number: '+str(ThreadCount))
ServerSocket.close()
Ejemplo 4: socket python del servidor cliente
s = socket.socket(socket_family, socket_type, protocol=0)
¡Haz clic para puntuar esta entrada!
(Votos: 0 Promedio: 0)