Loading ...
Sorry, an error occurred while loading the content.
 

Probably stupid newbie question about using sockets

Expand Messages
  • Andrei Formiga
    Hi, I m having trouble using the high-level network connection functions from the Unix module, that is, open_connection and shutdown_connection. For all I
    Message 1 of 3 , Dec 17, 2003
      Hi,

      I'm having trouble using the high-level network
      connection functions from the Unix module, that is,
      open_connection and shutdown_connection. For all I
      looked at the documentation I could not understand why
      things are happening like this. I'm using OCaml 3.07
      on Windows (native, not cygwin). A transcript of a
      test session follows.

      I first try to use the low-level Unix-like socket
      and file functions and everything is fine:

      # #load "Unix.cma";;
      # let irc_addr = Unix.ADDR_INET
      (Unix.inet_addr_of_string "200.199.102.186", 6667);;
      val irc_addr : Unix.sockaddr = Unix.ADDR_INET
      (<abstr>, 6667)
      # let irc_socket = Unix.socket Unix.PF_INET
      Unix.SOCK_STREAM 0;;
      val irc_socket : Unix.file_descr = <abstr>
      # let buffer = String.create 100;;
      val buffer : string =

      "\003\000\000\000\000\000\000\000�<I\000�\008B\000\001\000\000\000\000\000\000\000�<I\000��J\000\000+\000\000\001\000\000\000\001\000\000\000\001\000\000\000,\008B\000<yI\000\001\000\000\000(yI\000\001\000\000\000\001\000\000\000\028\008B\000�\011\000\0004xU\000\136\023J\000\000\023\000\000�!B\000T\030J\000"
      # Unix.connect irc_socket irc_addr;;
      - : unit = ()
      # Unix.read irc_socket buffer 0 100;;
      - : int = 100
      # buffer;;
      - : string =
      "NOTICE AUTH :*** Checking Ident\013\nNOTICE AUTH :***
      No Ident response\013\nPING
      :irc.brasnet.org\013\nERROR :C"
      # Unix.shutdown irc_socket Unix.SHUTDOWN_ALL;;
      - : unit = ()
      # Unix.close irc_socket;;
      - : unit = ()

      Then I try to use the high-level functions:

      # let irc_in, irc_out = Unix.open_connection
      irc_addr;;
      val irc_in : in_channel = <abstr>
      val irc_out : out_channel = <abstr>

      # input_line irc_in;;
      Exception: Sys_error "Bad file descriptor".

      # Unix.shutdown_connection irc_in;;
      Exception: Unix.Unix_error (Unix.ENOTSOCK, "shutdown",
      "").

      And that's it. The same error occurred in the many
      situations I've tried (Exception: Sys_error "Bad file
      descriptor"). Any hints ?

      Thanks in advance.

      ---
      []s, Andrei de A. Formiga


      __________________________________
      Do you Yahoo!?
      Protect your identity with Yahoo! Mail AddressGuard
      http://antispam.yahoo.com/whatsnewfree
    • Remi Vanicat
      ... [...] My test prove me that this seem to be an windows related problem. Then I read the unix library manual, and more precisely the porting stuff, where
      Message 2 of 3 , Dec 17, 2003
        Andrei Formiga <ktulu_fhtagn@...> writes:

        > Hi,
        >
        > I'm having trouble using the high-level network
        > connection functions from the Unix module, that is,
        > open_connection and shutdown_connection. For all I
        > looked at the documentation I could not understand why
        > things are happening like this. I'm using OCaml 3.07
        > on Windows (native, not cygwin). A transcript of a
        > test session follows.

        [...]

        My test prove me that this seem to be an windows related problem. Then
        I read the unix library manual, and more precisely the porting stuff,
        where one can read that :
        in_channel_of_descr: does not work on sockets under Windows 95, 98,
        ME; works fine under NT and 2000
        out_channel_of_descr: ditto

        The, when reading the implementation of open_connection it is clear
        that it use those 2 function. You should make a big report to the
        ocaml team telling them that this have to be wrote in the
        documentation...

        by the way, if you are using NT or 2000, then you should make a
        bug report too. And if you use XP you should make a bug report to ask
        them to add the XP status of those function.

        --
        Rémi Vanicat
      • Andrei Formiga
        ... I m using XP, so if it works under NT and 2000 I would expect it to work on my system. In theory at least. I ll report it to the OCaml team, and see what
        Message 3 of 3 , Dec 17, 2003
          --- Remi Vanicat <remi.vanicat@...> wrote:
          > The, when reading the implementation of
          > open_connection it is clear
          > that it use those 2 function. You should make a big
          > report to the
          > ocaml team telling them that this have to be wrote
          > in the
          > documentation...
          >
          > by the way, if you are using NT or 2000, then you
          > should make a
          > bug report too. And if you use XP you should make a
          > bug report to ask
          > them to add the XP status of those function.
          >

          I'm using XP, so if it works under NT and 2000 I
          would expect it to work on my system. In theory at
          least. I'll report it to the OCaml team, and see what
          gives. Thanks for answering.

          ---
          []s, Andrei de A. Formiga


          __________________________________
          Do you Yahoo!?
          Protect your identity with Yahoo! Mail AddressGuard
          http://antispam.yahoo.com/whatsnewfree
        Your message has been successfully submitted and would be delivered to recipients shortly.