chiSock FB socket library for Win/Lin

User projects written in or related to FreeBASIC.
Loe
Posts: 323
Joined: Apr 30, 2006 14:49

Postby Loe » Sep 16, 2007 4:42

I thought this thread closed.
Hi Chaos, I try your Chisock for file transferring.

client side

Code: Select all

dim so as chisock
dim x as integer
dim s as string

open "anyfile.dat" for binary as #1
x=lof(1)
s=string(x,0)
get #1,,s
close(1)
if so.send(x)=false then
    ?"error1"
elseif so.send(s)=false then
    ?"error2"
else
    ?"OK"
endif


server side

Code: Select all

dim so as chisock
dim x as integer
dim s as string

do
   if so.get(x) then
   s=string(x,0)
   so.dump_data(len(x))
       if so.get(s) then
           open "output.dat" for binary as #2
           put #2,,s
           close(2)
           so.dump_data(x)
        endif
   endif
loop until keypress


above code worked for small size file, say 100KB, but it will slowdown the system for bigsize file, say 100MB, with unpredictable result.
if I see your internal code of Chisock, it already threaded with chunk size of 1K, I assume I just send anysize of string.

Am I wrong? any help?
Oz
Posts: 585
Joined: Jul 02, 2005 14:21
Location: Waterloo, Ontario, Canada
Contact:

Postby Oz » Sep 16, 2007 14:55

I have fixed the putLine function. It turns out that there was a bunch of jibberish being sent (ascii codes less than 32) before my string, so this i the way i send lines to the irc server now:

Code: Select all

function sock.putLine( byval msg as string ) as integer

   dim m(0 to len( msg ) + 3 ) as ubyte
   dim i as integer
   m( len(msg)+1 ) = 13
   m( len(msg)+2 ) = 10
   m( len(msg)+3 ) = 0
   for i = 1 to len( msg )
      m( i -1 ) = cubyte( asc( mid( msg, i, 1 ) ) )
   next i

   return this.socketInside.put_data( @m(0), len( msg ) + 2 )

end function


perhaps someone will find that useful

Oz
Lachie Dazdarian
Posts: 2338
Joined: May 31, 2005 9:59
Location: Croatia
Contact:

Postby Lachie Dazdarian » Sep 16, 2007 16:45

The download link is dead. Where can I find the latest version of the lib for download?
sir_mud
Posts: 1401
Joined: Jul 29, 2006 3:00
Location: US
Contact:

Postby sir_mud » Sep 17, 2007 1:45

The latest version is hosted on c0de under the Projects sub-forum, or for non-c0de members i have mirrored it here: (edited out by cha0s)
Lachie Dazdarian
Posts: 2338
Joined: May 31, 2005 9:59
Location: Croatia
Contact:

Postby Lachie Dazdarian » Sep 17, 2007 20:24

Thanks!
wallyfblu
Posts: 69
Joined: May 24, 2006 10:58
Location: ITALY

Postby wallyfblu » Oct 27, 2007 19:58

Hi all, I've tried the library and it works well, but I needed a Win32 GUI interface and I had this errors when include "windows.bi"

C:/FreeBASIC/inc/chisock/socket.bi(151) error 7: Expected ')' in 'byval opaque as any ptr _'
C:/FreeBASIC/inc/chisock/socket.bi(156) error 7: Expected ')' in 'byval opaque as any ptr _'

Any idea about this problem? I'm using 0.18b
cha0s
Site Admin
Posts: 5317
Joined: May 27, 2005 6:42
Location: Illinois
Contact:

Postby cha0s » Jan 06, 2008 21:55

New release. This one has functioning UDP sockets, also speed limits for receiving/sending... and a couple undocumented (and therefore unsupported :P) functions.
vdecampo
Posts: 2982
Joined: Aug 07, 2007 23:20
Location: Maryland, USA
Contact:

Postby vdecampo » Jan 06, 2008 22:06

@cha0s
This is really cool stuff. I was thinking about writing a wrapper class that would provide non-blocking recieve methods that would trigger a callback when data is received or there is a connection/disconnect. Do you think something like that is possible?

-Vince
anonymous1337
Posts: 5494
Joined: Sep 12, 2005 20:06
Location: California

Postby anonymous1337 » Jan 06, 2008 22:15

This is amazing. We love you <3
cha0s
Site Admin
Posts: 5317
Joined: May 27, 2005 6:42
Location: Illinois
Contact:

Postby cha0s » Jan 06, 2008 22:20

vdecampo wrote:@cha0s
This is really cool stuff. I was thinking about writing a wrapper class that would provide non-blocking recieve methods that would trigger a callback when data is received or there is a connection/disconnect. Do you think something like that is possible?

-Vince


Yeah, it's possible, but I don't feel like implementing that. Feel free to wrap it and post, if you think it's solid.
cha0s
Site Admin
Posts: 5317
Joined: May 27, 2005 6:42
Location: Illinois
Contact:

Postby cha0s » Feb 18, 2008 22:02

Update... added the (as yet) undocumented function put_HTTP_request.
D.J.Peters
Posts: 8024
Joined: May 28, 2005 3:28
Contact:

Postby D.J.Peters » Mar 02, 2008 21:42

Hello cha0s good job
i wonder me a litle bit you use SELECT() together with none blocking server socket.

select() is primary for multiplexing blocking sockets (and pipes / file descriptors on uinix/linux)

If you use an none blocking socket why do you need SELECT() too ?
or if you use SELECT() why with none blocking server socket together ?
Do you set the the server socket in none blocking mode for Accept only ?

Joshy
cha0s
Site Admin
Posts: 5317
Joined: May 27, 2005 6:42
Location: Illinois
Contact:

Postby cha0s » Mar 02, 2008 23:01

It uses blocking sockets with seperate threads for recv/send.

iirc, Select is only used within the library to allow 'accept' to not block.
Oz
Posts: 585
Joined: Jul 02, 2005 14:21
Location: Waterloo, Ontario, Canada
Contact:

Postby Oz » Mar 02, 2008 23:16

I have an irc wrapper for anyone who is interested:
http://www.boxofoz.net/files/ircwrapper.zip

it's built on the latest chisock (not included)
assumes chisock is installed in
/FreeBASIC/inc/chisock and /lib/*
D.J.Peters
Posts: 8024
Joined: May 28, 2005 3:28
Contact:

Postby D.J.Peters » Mar 02, 2008 23:59

cha0s wrote:It uses blocking sockets...

For what is it &HFFFF,&H4 ?

thanx Joshy

Code: Select all

dim as integer reuse = C_TRUE
  if (setsockopt(from_socket , _
                 SOL_SOCKET  , _
                 SO_REUSEADDR, _
                 cast(any ptr, @reuse), _
                 len(integer) ) = SOCKET_ERROR ) then
      return FAILED_REUSE
  end if

Return to “Projects”

Who is online

Users browsing this forum: No registered users and 7 guests