Server (centos) -Client (windows) socket python and c

0

I have to simulate an ATM, where the centos server is made with python and the client in c (windows). I have ping when I do between the client and the server. Everything is perfect, but when interacting with the other machine, it is never possible to connect :(. E tested with thousands of codes.

Server python (Centos):

import socket
import threading

def conexiones(socket_cliente):
    peticion = socket_cliente.recv(1024)
    print ("[*] Mensaje recibido: %s" % peticion)
    socket_cliente.send("HOLA CLIENTE")
    socket_cliente.close()


ip = "192.168.1.101" 
puerto = 8888
max_conexiones = 5 
servidor = socket.socket(socket.AF_INET, socket.SOCK_STREAM)


servidor.bind((ip, puerto))
servidor.listen(max_conexiones)


print ("[*] Esperando conexiones en %s:%d" % (ip, puerto))


while True:
    cliente, direccion = servidor.accept()
    print ("[*] Conexion establecida con %s:%d" % (direccion[0] , direccion[1]))
    conexiones = threading.Thread(target=conexiones, args=(cliente,))
    conexiones.start()

Client C (windows)

#include<stdio.h>
#include<winsock2.h>

#pragma comment(lib,"ws2_32.lib") //Winsock Library
#define PORT 8888

int main(int argc , char *argv[])
{
    WSADATA wsa;
    SOCKET s;
    struct sockaddr_in server;
    char *message , server_reply[2000];
    int recv_size;

    printf("\nInicializando WinSock");
    if (WSAStartup(MAKEWORD(2,2),&wsa) != 0)
    {
        printf("Failed. Error Code : %d",WSAGetLastError());
        return 1;
    }

    printf("\nINICIALIZADO.\n");

    if((s = socket(AF_INET , SOCK_STREAM , 0 )) == INVALID_SOCKET)
    {
        printf("No fue posible crear socket : %d" , WSAGetLastError());
    }

    printf("Socket creado.\n");


    server.sin_addr.s_addr = inet_addr("192.168.1.101");
    server.sin_family = AF_INET;
    server.sin_port = htons( PORT );

    if (connect(s , (struct sockaddr *)&server , sizeof(server)) < 0)
    {
        puts("Error de conexión.");
        return 1;
    }

    puts("Conectado\n");

    if((recv_size = recv(s , server_reply , 2000 , 0)) == SOCKET_ERROR)
    {
        puts("recv falla");
    }

    puts("Respuesta recibida\n");

    server_reply[recv_size] = '
import socket
import threading

def conexiones(socket_cliente):
    peticion = socket_cliente.recv(1024)
    print ("[*] Mensaje recibido: %s" % peticion)
    socket_cliente.send("HOLA CLIENTE")
    socket_cliente.close()


ip = "192.168.1.101" 
puerto = 8888
max_conexiones = 5 
servidor = socket.socket(socket.AF_INET, socket.SOCK_STREAM)


servidor.bind((ip, puerto))
servidor.listen(max_conexiones)


print ("[*] Esperando conexiones en %s:%d" % (ip, puerto))


while True:
    cliente, direccion = servidor.accept()
    print ("[*] Conexion establecida con %s:%d" % (direccion[0] , direccion[1]))
    conexiones = threading.Thread(target=conexiones, args=(cliente,))
    conexiones.start()
'; puts(server_reply); return 0; }

Greetings. Thanks.

    
asked by felipe 08.06.2018 в 08:08
source

0 answers