Author | Topic: TCP/IP Socket Connection | |
---|---|---|
Naresh | TCP/IP Socket Connection on Fri, 07 Jul 2006 10:01:17 +0100 Hi, I am trying to get tcp/ip connection using nSocket := SocketOpen( SOCK_STREAM, cIP, nPort, @nErr ) (where cIP is an ip address of an external system (telephone pbx) which is plugged into the local network and I can ping that ip address from the pc where I run my program) I am getting error 11004 (Valid name, no data record of requested type) Can anyone tell what could the possible reason getting this error? Thanks in advance -Naresh | |
Jose Adriano Baltieri | Re: TCP/IP Socket Connection on Fri, 07 Jul 2006 10:22:41 -0300 Naresh wrote: > Hi, > > I am trying to get tcp/ip connection using > nSocket := SocketOpen( SOCK_STREAM, cIP, nPort, @nErr ) > (where cIP is an ip address of an external system (telephone pbx) which > is plugged into the local network and I can ping that ip address from > the pc where I run my program) > > I am getting error 11004 (Valid name, no data record of requested type) > > Can anyone tell what could the possible reason getting this error? > > Thanks in advance > > -Naresh Hello Naresh I think I had problems in the past with SocketOpen. You may want to try another approach, with SocketNew/SocketConnect. Here's the function I'm using for years and it's working perfectly fine. It connects to a mainframe. You may take it as an example to see how it's done. Good luck ! ############################################################################# FUNCTION SOCKET_CONNECT(LCHOST,LCCSSID,LASOCKET) LOCAL LCMENS, ; LNERROR:=0, ; LNSOCKET, ; LNDS, ; LNSTART, ; LNRCHARS:=0, ; LCIP LASOCKET:={} IF SLCOM_LOG FILEDELETE(SCPATH_LOG) END IF IF (LNSOCKET:=SOCKETNEW(AF_INET,SOCK_STREAM,IPPROTO_TCP)) == INVALID_SOCKET LNERROR:=SOCKETGETLASTERROR() COM_LOG("R",COM_PECHO("R",ERRO_TCPIP(LNERROR,0))) RETURN LNERROR END IF IF (LNERROR:=SOCKETGETLASTERROR()) <> 0 COM_LOG("R",COM_PECHO("R",ERRO_TCPIP(LNERROR,0))) RETURN LNERROR END IF COM_LOG("R",COM_PECHO("R","SOCKET OPENED OK !")) COM_LOG("E",COM_PECHO("E","CONNECTING TO SERVER...")) IF LCHOST == "DES" LCIP := "xxx.xx.xxx.xx" ELSEIF LCHOST == "PRO" LCIP := "xxx.xx.xxx.xx" ELSE ABORT : "HOST INVALIDO : " + LCHOST END IF IF NOT SOCKETCONNECT(LNSOCKET,AF_INET,LCIP,23) LNERROR:=SOCKETGETLASTERROR() COM_LOG("R",COM_PECHO("R",ERRO_TCPIP(LNERROR,0))) RETURN LNERROR END IF COM_LOG("E",COM_PECHO("E","SETTING NON BLOCKING MODE...")) IF NOT SOCKETSETBLOCKINGMODE(LNSOCKET,FALSE) LNERROR:=SOCKETGETLASTERROR() COM_LOG("R",COM_PECHO("R",ERRO_TCPIP(LNERROR,0))) RETURN LNERROR END IF COM_LOG("R",COM_PECHO("R","NON BLOCKING MODE SET OK !")) LNDS:=SOCKETFDSETNEW() IF LNDS == 0 LNERROR:=SOCKETGETLASTERROR() RETURN LNERROR END IF SOCKETFD_ZERO(LNDS,@LNERROR) IF LNERROR <> 0 RETURN LNERROR END IF IF NOT SOCKETFD_SET(LNSOCKET,LNDS) RETURN SOCKETGETLASTERROR() END IF LASOCKET:={LNSOCKET,LNDS,0,""} COM_LOG("R",COM_PECHO("R","SOCKET DESCRIPTOR SET OK !")) IF SLFIRST SCSPACES:=SPACE(TAMANHO_MAX_AREA) SLFIRST:=FALSE END IF WHILE TRUE LCMENS:=SOCKET_IRECEIVE(6,LNSOCKET) IF LCMENS == iac + do + suppress_go_ahead + iac + will + suppress_go_ahead SOCKET_IXMIT (iac + do + suppress_go_ahead + iac + will + suppress_go_ahead,LNSOCKET) COM_PECHO("R","TELNET CONNECTION NEGOTIATION 1") COM_PECHO("E","TELNET CONNECTION NEGOTIATION 2") ELSEIF LCMENS == iac + do + terminal_type + iac + do + send_location SOCKET_IXMIT (iac + will + terminal_type + iac + will + send_location,LNSOCKET) COM_PECHO("R","TELNET CONNECTION NEGOTIATION 3") COM_PECHO("E","TELNET CONNECTION NEGOTIATION 4") ELSEIF LCMENS == iac + sb + terminal_type + send + iac + se SOCKET_IXMIT (iac + sb + terminal_type + transmit_binary + "UNISYS-TD830" + iac + se,LNSOCKET) COM_PECHO("R","TELNET CONNECTION NEGOTIATION 5") COM_PECHO("E","TELNET CONNECTION NEGOTIATION 6") ELSEIF LCMENS == iac + do + end_of_record + iac + will + end_of_record SOCKET_IXMIT (iac + do + end_of_record + iac + will + end_of_record,LNSOCKET) COM_PECHO("R","TELNET CONNECTION NEGOTIATION 7") COM_PECHO("E","TELNET CONNECTION NEGOTIATION 8") ELSEIF LCMENS == iac + do + transmit_binary + iac + will + transmit_binary SOCKET_IXMIT (iac + do + transmit_binary + iac + will + transmit_binary,LNSOCKET) COM_PECHO("R","TELNET CONNECTION NEGOTIATION 9") COM_PECHO("E","TELNET CONNECTION NEGOTIATION 10") SOCKET_IXMIT (iac + sb + send_location + transmit_binary + LCCSSID + iac + se,LNSOCKET) EXIT END IF END WHILE COM_LOG("R",COM_PECHO("R","SOCKET PRE-CONNECTED OK !")) LCMENS:=SCSPACES LNSTART:=CSECONDS() WHILE LNRCHARS < 10 IF (LNRCHARS:=SOCKETRECV(LNSOCKET,@LCMENS,10,MSG_PEEK,@LNERROR)) == 0 IF LNERROR == 0 ; OR LNERROR == WSAEWOULDBLOCK IF CSECONDS() - LNSTART >= 30 SEGS RETURN -1 END IF SLEEP(10) LOOP END IF RETURN LNERROR END IF END WHILE COM_LOG("R",COM_PECHO("R",LCMENS)) IF LEFT(LCMENS,08) == "'?Ô<" ; OR LEFT(LCMENS,10) == "" + CHR(0) + "'?Ô?¶@@@" ; OR LEFT(LCMENS,10) == "" + CHR(0) + "'?Ô??@@@" OK ELSE RETURN -2 END IF COM_LOG("R",COM_PECHO("R","RECEIVED FIRST SCREEN !")) RETURN 0 ################################################################################## BTW, I also talk to our PBX but I do it using serial port. Which PBX is yours ? | |
Naresh | Re: TCP/IP Socket Connection on Fri, 14 Jul 2006 15:11:54 +0100 Jose, Thank you very much. It worked! Does that mean AsiNet help (which is not really helpful) says wrong that SocketOpen() is same as SocketNew() and SocketConnect()? Anyway, it is Samsung pbx. Thanks once again -Naresh Jose Adriano Baltieri wrote: > Naresh wrote: > >> Hi, >> >> I am trying to get tcp/ip connection using >> nSocket := SocketOpen( SOCK_STREAM, cIP, nPort, @nErr ) >> (where cIP is an ip address of an external system (telephone pbx) >> which is plugged into the local network and I can ping that ip address >> from the pc where I run my program) >> >> I am getting error 11004 (Valid name, no data record of requested type) >> >> Can anyone tell what could the possible reason getting this error? >> >> Thanks in advance >> >> -Naresh > > > Hello Naresh > > I think I had problems in the past with SocketOpen. > > You may want to try another approach, with SocketNew/SocketConnect. > > Here's the function I'm using for years and it's working perfectly fine. > It connects to a mainframe. You may take it as an example to see how > it's done. > > Good luck ! > > ############################################################################# > > FUNCTION SOCKET_CONNECT(LCHOST,LCCSSID,LASOCKET) > > LOCAL LCMENS, ; > LNERROR:=0, ; > LNSOCKET, ; > LNDS, ; > LNSTART, ; > LNRCHARS:=0, ; > LCIP > > LASOCKET:={} > > IF SLCOM_LOG > FILEDELETE(SCPATH_LOG) > END IF > > IF (LNSOCKET:=SOCKETNEW(AF_INET,SOCK_STREAM,IPPROTO_TCP)) == > INVALID_SOCKET > LNERROR:=SOCKETGETLASTERROR() > COM_LOG("R",COM_PECHO("R",ERRO_TCPIP(LNERROR,0))) > RETURN LNERROR > END IF > IF (LNERROR:=SOCKETGETLASTERROR()) <> 0 > COM_LOG("R",COM_PECHO("R",ERRO_TCPIP(LNERROR,0))) > RETURN LNERROR > END IF > COM_LOG("R",COM_PECHO("R","SOCKET OPENED OK !")) > COM_LOG("E",COM_PECHO("E","CONNECTING TO SERVER...")) > IF LCHOST == "DES" > LCIP := "xxx.xx.xxx.xx" > ELSEIF LCHOST == "PRO" > LCIP := "xxx.xx.xxx.xx" > ELSE > ABORT : "HOST INVALIDO : " + LCHOST > END IF > IF NOT SOCKETCONNECT(LNSOCKET,AF_INET,LCIP,23) > LNERROR:=SOCKETGETLASTERROR() > COM_LOG("R",COM_PECHO("R",ERRO_TCPIP(LNERROR,0))) > RETURN LNERROR > END IF > COM_LOG("E",COM_PECHO("E","SETTING NON BLOCKING MODE...")) > IF NOT SOCKETSETBLOCKINGMODE(LNSOCKET,FALSE) > LNERROR:=SOCKETGETLASTERROR() > COM_LOG("R",COM_PECHO("R",ERRO_TCPIP(LNERROR,0))) > RETURN LNERROR > END IF > COM_LOG("R",COM_PECHO("R","NON BLOCKING MODE SET OK !")) > > LNDS:=SOCKETFDSETNEW() > IF LNDS == 0 > LNERROR:=SOCKETGETLASTERROR() > RETURN LNERROR > END IF > SOCKETFD_ZERO(LNDS,@LNERROR) > IF LNERROR <> 0 > RETURN LNERROR > END IF > IF NOT SOCKETFD_SET(LNSOCKET,LNDS) > RETURN SOCKETGETLASTERROR() > END IF > > LASOCKET:={LNSOCKET,LNDS,0,""} > > COM_LOG("R",COM_PECHO("R","SOCKET DESCRIPTOR SET OK !")) > > IF SLFIRST > SCSPACES:=SPACE(TAMANHO_MAX_AREA) > SLFIRST:=FALSE > END IF > > WHILE TRUE > LCMENS:=SOCKET_IRECEIVE(6,LNSOCKET) > IF LCMENS == iac + do + suppress_go_ahead + iac + will + > suppress_go_ahead > SOCKET_IXMIT (iac + do + suppress_go_ahead + iac + will + > suppress_go_ahead,LNSOCKET) > COM_PECHO("R","TELNET CONNECTION NEGOTIATION 1") > COM_PECHO("E","TELNET CONNECTION NEGOTIATION 2") > ELSEIF LCMENS == iac + do + terminal_type + iac + do + send_location > SOCKET_IXMIT (iac + will + terminal_type + iac + will + > send_location,LNSOCKET) > COM_PECHO("R","TELNET CONNECTION NEGOTIATION 3") > COM_PECHO("E","TELNET CONNECTION NEGOTIATION 4") > ELSEIF LCMENS == iac + sb + terminal_type + send + iac + se > SOCKET_IXMIT (iac + sb + terminal_type + transmit_binary + > "UNISYS-TD830" + iac + se,LNSOCKET) > COM_PECHO("R","TELNET CONNECTION NEGOTIATION 5") > COM_PECHO("E","TELNET CONNECTION NEGOTIATION 6") > ELSEIF LCMENS == iac + do + end_of_record + iac + will + end_of_record > SOCKET_IXMIT (iac + do + end_of_record + iac + will + > end_of_record,LNSOCKET) > COM_PECHO("R","TELNET CONNECTION NEGOTIATION 7") > COM_PECHO("E","TELNET CONNECTION NEGOTIATION 8") > ELSEIF LCMENS == iac + do + transmit_binary + iac + will + > transmit_binary > SOCKET_IXMIT (iac + do + transmit_binary + iac + will + > transmit_binary,LNSOCKET) > COM_PECHO("R","TELNET CONNECTION NEGOTIATION 9") > COM_PECHO("E","TELNET CONNECTION NEGOTIATION 10") > SOCKET_IXMIT (iac + sb + send_location + transmit_binary + > LCCSSID + iac + se,LNSOCKET) > EXIT > END IF > END WHILE > > COM_LOG("R",COM_PECHO("R","SOCKET PRE-CONNECTED OK !")) > > LCMENS:=SCSPACES > LNSTART:=CSECONDS() > WHILE LNRCHARS < 10 > IF (LNRCHARS:=SOCKETRECV(LNSOCKET,@LCMENS,10,MSG_PEEK,@LNERROR)) == 0 > IF LNERROR == 0 ; > OR LNERROR == WSAEWOULDBLOCK > IF CSECONDS() - LNSTART >= 30 SEGS > RETURN -1 > END IF > SLEEP(10) > LOOP > END IF > RETURN LNERROR > END IF > END WHILE > > COM_LOG("R",COM_PECHO("R",LCMENS)) > > IF LEFT(LCMENS,08) == "'?Ô<" ; > OR LEFT(LCMENS,10) == "" + CHR(0) + "'?Ô?¶@@@" ; > OR LEFT(LCMENS,10) == "" + CHR(0) + "'?Ô??@@@" > OK > ELSE > RETURN -2 > END IF > > COM_LOG("R",COM_PECHO("R","RECEIVED FIRST SCREEN !")) > > RETURN 0 > ################################################################################## > > > > > > > > > > > > > BTW, I also talk to our PBX but I do it using serial port. Which PBX is > yours ? > > | |
Jose Adriano Baltieri | Re: TCP/IP Socket Connection on Fri, 14 Jul 2006 14:45:59 -0300 Naresh wrote: > Jose, > > Thank you very much. > It worked! I'm glad it worked for you ! > Does that mean AsiNet help (which is not really helpful) says > wrong that SocketOpen() is same as SocketNew() and SocketConnect()? Yes, it says it's the same but, I dont know why it never worked for me. > Anyway, it is Samsung pbx. OK. > Thanks once again > > -Naresh > > Jose Adriano Baltieri wrote: >> Naresh wrote: >> >>> Hi, >>> >>> I am trying to get tcp/ip connection using >>> nSocket := SocketOpen( SOCK_STREAM, cIP, nPort, @nErr ) >>> (where cIP is an ip address of an external system (telephone pbx) >>> which is plugged into the local network and I can ping that ip >>> address from the pc where I run my program) >>> >>> I am getting error 11004 (Valid name, no data record of requested type) >>> >>> Can anyone tell what could the possible reason getting this error? >>> >>> Thanks in advance >>> >>> -Naresh >> >> >> Hello Naresh >> >> I think I had problems in the past with SocketOpen. >> >> You may want to try another approach, with SocketNew/SocketConnect. >> >> Here's the function I'm using for years and it's working perfectly >> fine. It connects to a mainframe. You may take it as an example to see >> how it's done. >> >> Good luck ! >> >> ############################################################################# >> >> FUNCTION SOCKET_CONNECT(LCHOST,LCCSSID,LASOCKET) >> >> LOCAL LCMENS, ; >> LNERROR:=0, ; >> LNSOCKET, ; >> LNDS, ; >> LNSTART, ; >> LNRCHARS:=0, ; >> LCIP >> >> LASOCKET:={} >> >> IF SLCOM_LOG >> FILEDELETE(SCPATH_LOG) >> END IF >> >> IF (LNSOCKET:=SOCKETNEW(AF_INET,SOCK_STREAM,IPPROTO_TCP)) == >> INVALID_SOCKET >> LNERROR:=SOCKETGETLASTERROR() >> COM_LOG("R",COM_PECHO("R",ERRO_TCPIP(LNERROR,0))) >> RETURN LNERROR >> END IF >> IF (LNERROR:=SOCKETGETLASTERROR()) <> 0 >> COM_LOG("R",COM_PECHO("R",ERRO_TCPIP(LNERROR,0))) >> RETURN LNERROR >> END IF >> COM_LOG("R",COM_PECHO("R","SOCKET OPENED OK !")) >> COM_LOG("E",COM_PECHO("E","CONNECTING TO SERVER...")) >> IF LCHOST == "DES" >> LCIP := "xxx.xx.xxx.xx" >> ELSEIF LCHOST == "PRO" >> LCIP := "xxx.xx.xxx.xx" >> ELSE >> ABORT : "HOST INVALIDO : " + LCHOST >> END IF >> IF NOT SOCKETCONNECT(LNSOCKET,AF_INET,LCIP,23) >> LNERROR:=SOCKETGETLASTERROR() >> COM_LOG("R",COM_PECHO("R",ERRO_TCPIP(LNERROR,0))) >> RETURN LNERROR >> END IF >> COM_LOG("E",COM_PECHO("E","SETTING NON BLOCKING MODE...")) >> IF NOT SOCKETSETBLOCKINGMODE(LNSOCKET,FALSE) >> LNERROR:=SOCKETGETLASTERROR() >> COM_LOG("R",COM_PECHO("R",ERRO_TCPIP(LNERROR,0))) >> RETURN LNERROR >> END IF >> COM_LOG("R",COM_PECHO("R","NON BLOCKING MODE SET OK !")) >> >> LNDS:=SOCKETFDSETNEW() >> IF LNDS == 0 >> LNERROR:=SOCKETGETLASTERROR() >> RETURN LNERROR >> END IF >> SOCKETFD_ZERO(LNDS,@LNERROR) >> IF LNERROR <> 0 >> RETURN LNERROR >> END IF >> IF NOT SOCKETFD_SET(LNSOCKET,LNDS) >> RETURN SOCKETGETLASTERROR() >> END IF >> >> LASOCKET:={LNSOCKET,LNDS,0,""} >> >> COM_LOG("R",COM_PECHO("R","SOCKET DESCRIPTOR SET OK !")) >> >> IF SLFIRST >> SCSPACES:=SPACE(TAMANHO_MAX_AREA) >> SLFIRST:=FALSE >> END IF >> >> WHILE TRUE >> LCMENS:=SOCKET_IRECEIVE(6,LNSOCKET) >> IF LCMENS == iac + do + suppress_go_ahead + iac + will + >> suppress_go_ahead >> SOCKET_IXMIT (iac + do + suppress_go_ahead + iac + will >> + suppress_go_ahead,LNSOCKET) >> COM_PECHO("R","TELNET CONNECTION NEGOTIATION 1") >> COM_PECHO("E","TELNET CONNECTION NEGOTIATION 2") >> ELSEIF LCMENS == iac + do + terminal_type + iac + do + >> send_location >> SOCKET_IXMIT (iac + will + terminal_type + iac + will + >> send_location,LNSOCKET) >> COM_PECHO("R","TELNET CONNECTION NEGOTIATION 3") >> COM_PECHO("E","TELNET CONNECTION NEGOTIATION 4") >> ELSEIF LCMENS == iac + sb + terminal_type + send + iac + se >> SOCKET_IXMIT (iac + sb + terminal_type + transmit_binary >> + "UNISYS-TD830" + iac + se,LNSOCKET) >> COM_PECHO("R","TELNET CONNECTION NEGOTIATION 5") >> COM_PECHO("E","TELNET CONNECTION NEGOTIATION 6") >> ELSEIF LCMENS == iac + do + end_of_record + iac + will + end_of_record >> SOCKET_IXMIT (iac + do + end_of_record + iac + will + >> end_of_record,LNSOCKET) >> COM_PECHO("R","TELNET CONNECTION NEGOTIATION 7") >> COM_PECHO("E","TELNET CONNECTION NEGOTIATION 8") >> ELSEIF LCMENS == iac + do + transmit_binary + iac + will + >> transmit_binary >> SOCKET_IXMIT (iac + do + transmit_binary + iac + will + >> transmit_binary,LNSOCKET) >> COM_PECHO("R","TELNET CONNECTION NEGOTIATION 9") >> COM_PECHO("E","TELNET CONNECTION NEGOTIATION 10") >> SOCKET_IXMIT (iac + sb + send_location + transmit_binary >> + LCCSSID + iac + se,LNSOCKET) >> EXIT >> END IF >> END WHILE >> >> COM_LOG("R",COM_PECHO("R","SOCKET PRE-CONNECTED OK !")) >> >> LCMENS:=SCSPACES >> LNSTART:=CSECONDS() >> WHILE LNRCHARS < 10 >> IF (LNRCHARS:=SOCKETRECV(LNSOCKET,@LCMENS,10,MSG_PEEK,@LNERROR)) == 0 >> IF LNERROR == 0 ; >> OR LNERROR == WSAEWOULDBLOCK >> IF CSECONDS() - LNSTART >= 30 SEGS >> RETURN -1 >> END IF >> SLEEP(10) >> LOOP >> END IF >> RETURN LNERROR >> END IF >> END WHILE >> >> COM_LOG("R",COM_PECHO("R",LCMENS)) >> >> IF LEFT(LCMENS,08) == "'?Ô<" ; >> OR LEFT(LCMENS,10) == "" + CHR(0) + "'?Ô?¶@@@" ; >> OR LEFT(LCMENS,10) == "" + CHR(0) + "'?Ô??@@@" >> OK >> ELSE >> RETURN -2 >> END IF >> >> COM_LOG("R",COM_PECHO("R","RECEIVED FIRST SCREEN !")) >> >> RETURN 0 >> ################################################################################## >> >> >> >> >> >> >> >> >> >> >> >> >> BTW, I also talk to our PBX but I do it using serial port. Which PBX >> is yours ? >> >> | |
Pascal Boivin | Re: TCP/IP Socket Connection on Thu, 14 Jul 2016 16:52:23 +0200 I got error 11004 for only one IP using SocketOpen. Program was OK a few days before (Windows Update?) I discovered this thread written 10 years ago and it solved my problem! Thank you |