Alaska Software Inc. - winsock usage
Username: Password:
AuthorTopic: winsock usage
Claudio Driussi winsock usage
on Fri, 04 Aug 2006 15:22:20 +0200
I wrote a little client server application which demostrate
the winsock ocx component usage.

I is a simple chat between client and server through TCP protocol

I attach the two files.

Off course it require XPP 1.9

Claudio.


server.prg
client.prg
eldhoseRe: winsock usage
on Thu, 26 Jun 2008 10:51:29 +0530
"Claudio Driussi" <claudio.driussi@libero.it> wrote in message 
news:19afe0fb$30be7646$b6e27@news.alaska-software.com...
>I wrote a little client server application which demostrate
> the winsock ocx component usage.
>
> I is a simple chat between client and server through TCP protocol
>
> I attach the two files.
>
> Off course it require XPP 1.9
>
> Claudio.
>
>


--------------------------------------------------------------------------------


> #pragma library( "ascom10.lib" )
> PROCEDURE MAIN
>  LOCAL o,x,buf := ""
>
>  o := CreateObject( "MSWinsock.Winsock" )
>  o := o:dynamicCast( "ActiveXObject" )
>  o:DataArrival := {|nBytes|_dataArrival(nBytes,o)}
>  o:ConnectionRequest := {|nRequestID|_ConnectionRequest(nRequestID,o)}
>
>  o:LocalPort  := 1007
>  o:protocol   := 0
>  print('LocalHostName: ',o:localHostName)
>  print('LocalIP: ',o:localIP)
>  print('Listening on port: ',o:LocalPort)
>  o:Listen()
>   o:AboutBox()      if you like...
>
>  ?
>  ? "Press ESC to terminate."
>  while .t.
>    if (x := inkey(0.01)) == 27 ; exit ; endif
>    if x != 0
>      buf += chr(x)
>      ?? chr(x)
>      if o:state == 7
>        o:sendData(buf)
>        buf := ""
>        endif
>      endif
>    enddo
>
>  o:close()
> RETURN
>
> function print(cDsc,xVal)
>  ? cDsc
>  ?? xVal
> return nil
>
> function _dataArrival(nBytes,o)
>  local i,s := s := space(nBytes)
>  o:getData(@s)
>  ?? s
> return nil
>
> function _ConnectionRequest(nRequestID,o)
>  print('request: ',nRequestID)
>  print('from: ',o:RemoteHostIP)
>  if o:state != 0 ; o:close() ; endif
>  ?
>  o:Accept(nRequestID)
>  o:sendData("Connection accepted...")
> return nil
>
>


--------------------------------------------------------------------------------


> #pragma library( "ascom10.lib" )
> PROCEDURE MAIN
>  LOCAL o,x,buf := ""
>
>  o := CreateObject( "MSWinsock.Winsock" )
>  o := o:dynamicCast( "ActiveXObject" )
>  o:DataArrival := {|nBytes|_dataArrival(nBytes,o)}
>  o:Connect     := {||_Connect(o)}
>
>  o:RemoteHost := o:localIP
>  o:RemotePort := 1007
>  o:protocol   := 0
>  o:Connect()
>
>  ?
>  ? "Press ESC to terminate."
>  while .t.
>    if (x := inkey(0.01)) == 27 ; exit ; endif
>    if x != 0
>      buf += chr(x)
>      ?? chr(x)
>      if o:state == 7
>        o:sendData(buf)
>        buf := ""
>        endif
>      endif
>    enddo
>
>  o:close()
> RETURN
>
> function print(cDsc,xVal)
>  ? cDsc
>  ?? xVal
> return nil
>
> function _dataArrival(nBytes,o)
>  local i,s := s := space(nBytes)
>  o:getData(@s)
>  ?? s
> return nil
>
> function _Connect(o)
>  ? "Connected..."
>  ?
> return nil
>
>