На главную Наши проекты:
Журнал   ·   Discuz!ML   ·   Wiki   ·   DRKB   ·   Помощь проекту
ПРАВИЛА FAQ Помощь Участники Календарь Избранное RSS
msm.ru
Модераторы: Qraizer, Hsilgos
  
> UNIX Socket , вопрос !
    Помогите пожалуста с соктами разабратза
    Я создал socket ...
    ExpandedWrap disabled
       
        sock_desc = socket(PF_INET, SOCK_STREAM, 0);
        if (sock_desc == -1) {
           perror("cannot create socket for client");
           exit(EXIT_FAILURE);
        }
       
        /* Set up the address structure in accordance with the server we are connecting to */
       
        sock_address.sin_family = PF_INET;
        sock_address.sin_port = 9734;
        sock_address.sin_addr.s_addr = inet_addr("192.168.10.254");


    и он работает толика с UNIX сервер с Windows-a не хочет
    Можна какта присоеденится к Windows Server ?
      Мда... nеоритически такого быть не может...

      А дальше что? Это сервер или клиент? Выложи весь код.
        Это клиент
        ExpandedWrap disabled
           
          #include <stdio.h>
          #include <stdlib.h>
          #include <string.h>
          #include <sys/types.h>
          #include <sys/socket.h>
          #include <unistd.h>
          #include <netinet/in.h>
          #include <arpa/inet.h>
          #include <ctype.h>
           
          int main(int argc, char *argv[])
          {
           
            int sock_desc;
            struct sockaddr_in sock_address;
            int connect_result;
            char *cbuff, *readbuff;
           
            readbuff = (char *)malloc(sizeof(double));
            if (!readbuff) {
              perror("Memory allocation failure");
              exit(EXIT_FAILURE);
            }
           
            if (argc < 2) {
              fprintf(stderr, "Usage is: $ local-client1 [double value] \n");
              exit(EXIT_FAILURE);
            }
            else if (argc > 2) {
              fprintf(stderr, "Too many arguments! \n");
              fprintf(stderr, "Usage is: $ local-client1 [double value] \n");
              exit(EXIT_FAILURE);
            }
            else if (argc == 2) {
              cbuff = argv[1];
              while (*cbuff != '\0') {
                if (isdigit(*cbuff) || *cbuff == '.')
                    cbuff++;
                else {
                    fprintf(stderr, "Illegal value provided as argument \n");
                    exit(EXIT_FAILURE);
                }
              }
            }
           
            /* Create the socket to be used for the client to connect to the server */
           
            sock_desc = socket(PF_INET, SOCK_STREAM, 0);
            if (sock_desc == -1) {
               perror("cannot create socket for client");
               exit(EXIT_FAILURE);
            }
           
            /* Set up the address structure in accordance with the server we are connecting to */
           
            sock_address.sin_family = PF_INET;
            sock_address.sin_port = 9734;
            sock_address.sin_addr.s_addr = inet_addr("192.168.10.254");
           
           
            /* make a connection to the server via the "connect()" function */
           
            connect_result = connect(sock_desc, (struct sockaddr *)&sock_address, sizeof(sock_address));
           
            if (connect_result == -1) {
              perror("Cannot establish a server connection");
              exit(EXIT_FAILURE);
            }
            else
              printf("Server connection successfull, we are connected to the server \n");
              
           
            /* Read and write to and from the server */
           
            write(sock_desc, argv[1], sizeof(double));
            read(sock_desc, readbuff, sizeof(double));
            printf("Based on the response received from the server\n");
            printf("The square root of %s \n", readbuff);
            read(sock_desc, readbuff, sizeof(double));
            printf(" is %s. \n", readbuff);
           
            read(sock_desc, readbuff, sizeof(double));
            printf(" is %s. \n", readbuff);
           
          /* Close the socket once we are finished reading and writing to/from it */
            
            close(sock_desc);
           
           exit(EXIT_SUCCESS);
           
          }
          Попробуй следующее:
          1) замени PF_INET на AF_INET
          2) обнули sock_address перед заполнением bzero(&sock_address, sizeof(sock_address))
          3) если не заработает - проверь правильно ли работает виндовый сервер (например напиши такой-же клиент но под виндой)
            и ещё: по моему лучше так:

            sock_address.sin_port = 9734;

            попробуй заменить на

            sock_address.sin_port = htons(9734);
              У меня сервер поостроен с помощю class в MFC Visual c++ и не получяетца присоединеие
                Цитата visual,8.02.04, 02:36
                У меня сервер поостроен с помощю class в MFC Visual c++ и не получяетца присоединеие

                А клиент полностью аналогичный тому что ты приводил, но под виндой конектиться?
                0 пользователей читают эту тему (0 гостей и 0 скрытых пользователей)
                0 пользователей:


                Рейтинг@Mail.ru
                [ Script execution time: 0,0246 ]   [ 16 queries used ]   [ Generated: 1.05.24, 12:59 GMT ]