Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Using Mabry Socket/X control from vfp
Message
General information
Forum:
Visual FoxPro
Category:
Internet applications
Miscellaneous
Thread ID:
00518847
Message ID:
00523997
Views:
20
If packet doesn't contain chr(0)s, all is OK.
If packed contains chr(0)s, some of them are replaced with random characters.

>Let me understand: if you don't send chr(0), is the data correct, or is it also corrupted?
>
>>Thank you, this code sends and receives data.
>>However, it corrupts data! I always got back some other characters than
>>zeroes: an Error text is produces by this program.
>>If I change CHR(0) to some other character, for example
>>
>>cBuffer = REPLICATE( CHR(1), 100 )
>>
>>Is it possible to send 00 characters without data corruption ?
>>
>>
>>>I think there are some glitches in your code. First, you should remember that your connection is never 8 MBPS and up, so always give some time between your send and your receive command. I guess the code that you showed me runs undefinetly because cStr is probably always empty.
>>>The following is the way i would implement what you want to do, tell me if it works ok:
>>>
>>>** form.init method
>>>ACTIVATE SCREEN
>>>CLEAR
>>>ON SHUTDOWN QUIT
>>>SET TALK OFF
>>>SET ECHO OFF
>>>
>>>with ThisForm
>>>   .OleControl1.LocalAddress = "194.106.108.233" &&& your ip
>>>   .OleControl1.LocalPort = 0
>>>   .OleControl1.Create()
>>>   .OleControl1.RemoteNameAddrXlate = .T.
>>>   .OleControl1.RemoteName = "pepe.online.ee"
>>>   .OleControl1.RemotePort = 7
>>>   .OleControl1.Blocking = .F.
>>>   .OleControl1.ConnectTimeout = 5
>>>   .OleControl1.object.Connect()
>>>endwith
>>>
>>>DO WHILE THIS.olecontrol1.state!=4
>>>  IF INKEY(0.5)=27
>>>    RETURN .F.
>>>    ENDIF
>>>  ? 'Connecting', THIS.olecontrol1.lasterrorstring
>>>ENDDO
>>>
>>>m.cBuffer = REPLICATE( CHR(0), 100 )
>>>local dummyWait
>>>
>>>DO WHILE INKEY(.5)!=27 and THIS.olecontrol1.state=4
>>>  This.OleControl1.SendBuffer = m.CBuffer &&& you don't need CREATEBINARY
>>>  THIS.OleControl1.object.Send()
>>>  dummyWait = inkey(3) &&& waits 3 seconds to give some time to the send
>>>  CStr = ''
>>>  DO WHILE INKEY(.5)!=27 and THIS.olecontrol1.state=4 AND EMPTY(cStr)
>>>    THIS.OleControl1.object.receive()
>>>    cStr = this.olecontrol1.receivebuffer
>>>    ? THIS.olecontrol1.lasterrorstring
>>>  ENDDO
>>>
>>>  ?'Received', len(cStr), cStr
>>>  IF cStr!=m.cBuffer
>>>     ?? 'Error'
>>>   ELSE
>>>    ?? 'OK'
>>>    ENDIF
>>>  ENDDO
>>>RETURN .F.
>>>
>>>
>>>
>>>
>>>
>>>
>>>>Jaime, thank yor for help. I tried to use your code and produces the following program. This program doesn't receive any data (receive buffer is empty):
>>>>an infinite loops occurs if calling receive command
>>>>and no error occurs. If I implement the same thing using MSWINSOCK, it works. Can you point me what is wrong with this code ?
>>>>
>>>>
>>>>** form.init method
>>>>ACTIVATE SCREEN
>>>>CLEAR
>>>>ON SHUTDOWN QUIT
>>>>SET TALK OFF
>>>>SET ECHO OFF
>>>>
>>>>with ThisForm
>>>>   .OleControl1.LocalAddress = "194.106.108.233" &&& your ip
>>>>   .OleControl1.LocalPort = 0
>>>>   .OleControl1.Create()
>>>>    .OleControl1.RemoteNameAddrXlate = .T.
>>>>    .OleControl1.RemoteName = "pepe.online.ee"
>>>>   .OleControl1.RemotePort = 7
>>>>   .OleControl1.Blocking = .F.
>>>>   .OleControl1.ConnectTimeout = 5
>>>>   .OleControl1.object.Connect()
>>>>endwith
>>>>
>>>>DO WHILE THIS.olecontrol1.state!=4
>>>>  IF INKEY(0.5)=27
>>>>    RETURN .F.
>>>>    ENDIF
>>>>  ? 'Connecting', THIS.olecontrol1.lasterrorstring
>>>>  ENDDO
>>>>
>>>>cBuffer = REPLICATE( CHR(0), 100 )
>>>>
>>>>DO WHILE INKEY(.5)!=27 and THIS.olecontrol1.state=4
>>>>  THIS.olecontrol1.send( CREATEBINARY(m.cBuffer) )
>>>>  CStr = ''
>>>>  * ??????????????????????????????????????????????????
>>>>  * The following loop will run infinitely. Why ?
>>>>  DO WHILE INKEY(.5)!=27 and THIS.olecontrol1.state=4 AND EMPTY(cStr)
>>>>    THIS.olecontrol1.receive(1)
>>>>    cStr = this.olecontrol1.receivebuffer
>>>>    ? THIS.olecontrol1.lasterrorstring
>>>>    ENDDO
>>>>
>>>>  ?'Received', len(cStr), cStr
>>>>  IF cStr!=m.cBuffer
>>>>     ?? 'Error'
>>>>   ELSE
>>>>    ?? 'OK'
>>>>    ENDIF
>>>>  ENDDO
>>>>RETURN .F.
>>>>
>>>>
>>>>>Your code doesn't seem to connect the right way. If your Socket/X control's name is olecontrol1, your should start by doing something like this to connec:
>>>>>
>>>>>with ThisForm
>>>>>   .OleControl1.LocalAddress = "192.168.1.1" &&& your ip
>>>>>   .OleControl1.LocalPort = 0
>>>>>   .OleControl1.Create()
>>>>>   *** if you connect by ip address, you should do then
>>>>>    .OleControl1.RemoteNameAddrXlate = .F.
>>>>>    .OleControl1.RemoteAddress = "212.155.99.148"  &&& other side's ip
>>>>>   *** otherwise if you connect by name
>>>>>    .OleControl1.RemoteNameAddrXlate = .T.
>>>>>    .OleControl1.RemoteName = "www.eetasoft.ee"
>>>>>
>>>>>   .OleControl1.RemotePort = 7
>>>>>   .OleControl1.Blocking = .F.
>>>>>   *** now set a connection timeout, let's say 5 seconds
>>>>>   .OleControl1.ConnectTimeout = 5
>>>>>
>>>>>   *** finally connect...
>>>>>   .OleControl1.object.Connect()
>>>>>endwith
>>>>>
>>>>>Now, if you check ThisForm.OleControl1.State, it should really be 4 and then you can go on with the data transmissions.
>>>>>
>>>>>Cheers,
>>>>>Jaime
>>>>>
>>>>>>I need to send and receive 00 bytes from tcp port.
>>>>>>I have found that ms winsock control corrupts tcp packets containing 00
>>>>>>bytes.
>>>>>>
>>>>>>So I desided to use Mabry Socket/X control.
>>>>>>
>>>>>>I made a simple test program. This program sends TCP packets to port 7
>>>>>>and receives data from this port.
>>>>>>
>>>>>>I dropped Socket/X control to vfp 5 form and added the following code
>>>>>>to form init :
>>>>>>
>>>>>>ACTIVATE SCREEN
>>>>>>CLEAR
>>>>>>ON SHUTDOWN QUIT
>>>>>>THIS.olecontrol1.CREATE()
>>>>>>DO WHILE THIS.olecontrol1.state!=3
>>>>>> IF INKEY()=27
>>>>>> RETURN .F.
>>>>>> ENDIF
>>>>>> ? THIS.olecontrol1.lasterrorstring, THIS.olecontrol1.state
>>>>>> ENDDO
>>>>>>
>>>>>>THIS.olecontrol1.CONNECT( 'www.eetasoft.ee', 7 )
>>>>>>
>>>>>>DO WHILE THIS.olecontrol1.state!=4
>>>>>> IF INKEY()=27
>>>>>> RETURN .F.
>>>>>> ENDIF
>>>>>> ? THIS.olecontrol1.lasterrorstring, THIS.olecontrol1.state
>>>>>> ENDDO
>>>>>>
>>>>>>cBuffer = REPLICATE( CHR(0), 100 )
>>>>>>
>>>>>>DO WHILE INKEY()!=27
>>>>>> THIS.olecontrol1.sendto('www.eetasoft.ee', 7, m.cBuffer )
>>>>>> THIS.olecontrol1.receivefrom('www.eetasoft.ee', 7 )
>>>>>> ? THIS.olecontrol1.lasterrorstring, THIS.olecontrol1.state
>>>>>> IF LEN(THIS.olecontrol1.receivebuffer)!=100 or ;
>>>>>> THIS.olecontrol1.receivebuffer!=m.cBuffer
>>>>>> ?? 'Error'
>>>>>> ELSE
>>>>>> ?? 'OK'
>>>>>> ENDIF
>>>>>> ENDDO
>>>>>>
>>>>>>RETURN .F.
>>>>>>
>>>>>>
>>>>>>However, this code does not cause any internet access at all.
>>>>>>.State after .create() remains 3
>>>>>>
>>>>>>Is it possible to use Mabry Socket/X with VFP ?
Andrus
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform