Important alert: (current site time 7/16/2013 2:55:06 AM EDT)
 

winzip icon

CSocketMaster - Winsock API implementation class

Email
Submitted on: 3/1/2004 1:42:49 AM
By: Emiliano Scavuzzo 
Level: Advanced
User Rating: By 72 Users
Compatibility: VB 6.0
Views: 68450
(About the author)
 
     CSocketMaster class is a winsock control substitute. It has the same interface and behavior winsock has so don't worry about having to learn how to use it. If you know how winsock works then you already know how CSocketMaster works. You can use a socket in a form, user control or class without external dependencies or huge memory leaking OCXs. Do you still prefer a user control? No hay problema! Check the samples and learn how ridiculous easy you can make a winsock control clone in less than 20 minutes (d@mn! I love encapsulation). Did I mention it's IDE safe? That's right, you can press the end button all you want and wont get a GPF. Take a look at the readme file for more info. This is my first post ever, please vote! This code is based on CSocket by Oleg Gdalevich that can be found on www.vbip.com (CSocket => CSocketMaster) Keywords: socket, winsock, tcp, udp, internet, lan.

 
winzip iconDownload code

Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. Afterdownloading it, you will need a program like Winzip to decompress it.Virus note:All files are scanned once-a-day by Planet Source Code for viruses, but new viruses come out every day, so no prevention program can catch 100% of them. For your own safety, please:
  1. Re-scan downloaded files using your personal virus checker before using it.
  2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.
  3. Scan the source code with Minnow's Project Scanner

If you don't have a virus scanner, you can get one at many places on the net including:McAfee.com

 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.


Other 2 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Advanced category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments

3/1/2004 2:04:04 AMTechni Rei Myoko

I love winsock replacements. One less dependancy the better
(If this comment was disrespectful, please report it.)

 
3/1/2004 2:27:02 AMDavid C. Thompson

Yeah, having to install OCX files all the time is a mission. Much better. Hope it works though.
(If this comment was disrespectful, please report it.)

 
3/1/2004 2:34:52 AMNoRabbit

looks like the cSocket class from www.vbip.com
(If this comment was disrespectful, please report it.)

 
3/1/2004 3:05:20 AMEmiliano Scavuzzo

NoRabbit:
Yes, it looks like cSocket from Oleg Gdalevich because it's based on it. I commented this on the credits (take a look). But cSocket is quite incomplete.
(If this comment was disrespectful, please report it.)

 
3/1/2004 5:20:09 AMNoRabbit

Sorry, I had not seen it.
You should put it in your comment... (this is more sympathetic for the author)

I just have one question : what is the purpose of the subclass.asm ?
(If this comment was disrespectful, please report it.)

 
3/1/2004 6:07:24 AMLight Templer

Me too: Give credits to Oleg Gdalevich (www.vbip.com) in your PSC description and tell there what is changed/improved! Thats fair use.
LiTe
(If this comment was disrespectful, please report it.)

 
3/1/2004 6:26:04 AMLight Templer

After a closer look: God job, you changed a lot! One hint: You declared: 'VB5/VB6' - Thats wrong - e.g. BuildArray(...) As Byte() cannot run in VB5, or 'BuildArray()' in RecvData() isn't defined ...
Regards LiTe
(If this comment was disrespectful, please report it.)

 
3/1/2004 2:17:47 PMEmiliano Scavuzzo

NoRabbit:
The comment was changed to give credits to Oleg Gdalevich. About the Subclass.asm file, it is the assembler source code I use as a WndProc on the subclassing approach. It's based on WinSubHook2 by Paul Caton that can be found on this site. Sorry for that, the only thing worst than my english is my assembler. Note that this file isn't needed at all.
(If this comment was disrespectful, please report it.)

 
3/1/2004 2:18:29 PMEmiliano Scavuzzo

Light Templer:
Sorry for the VB5 error, I'd changed it. I don't have VB5 so I mistakenly assumed that would work. Maybe this can be fixed, if someone with VB5 knows which parts of my code doesn't work on VB5, please email me and I'll try to repair it.
(If this comment was disrespectful, please report it.)

 
3/1/2004 2:18:57 PMEmiliano Scavuzzo

About CSocket:
I used CSocket as a guide, I didn't just cut and paste this guy code. In fact 90% of the non-subclassing code was made from scratch. I DID copy some code from CSocket, like the help functions (IntegerToUnsigned, UnsignedToInteger, StringFromPointer) and the code that turns a variant into byte arrays and contrariwise (Send and GetData function). The reason they look so alike it's because they do the same thing.
(If this comment was disrespectful, please report it.)

 
3/1/2004 4:26:44 PMPhantom Man

Excellent.

I've Always Hated Using The Winsock Control. Now I Will Never Look At It Again

Very Nice.
(If this comment was disrespectful, please report it.)

 
3/1/2004 4:51:40 PMzoom

I love this code it works great. No bugs yet and im playing with it a lot. way to go :D
(If this comment was disrespectful, please report it.)

 
3/1/2004 4:53:40 PMPaul Caton

Good work - you've made a number of modifications to my original code, so clearly, you fully understand it - I'm impressed. This is what I work for.. that others will build on it. Well done.
(If this comment was disrespectful, please report it.)

 
3/1/2004 6:03:30 PMLuke H.

Just an idea, but what would you think about an IWSA or similar interface to receive the events? You could have a long value Tag or some similar property that would be the first argument for each callback method. Then you could have a collection or an array of cSocketMasters, and give them all your form(or other object), so all the benefits of a control array without the overhead or the requirement for a form. Plus, you could change the Callback object at run time, and the callbacks would not be subject to all the unnecessary overhead of an event. The only thing is that it would no longer be a drop-in replacement for a Winsock control, you'd have to move all the event code to the callback methods, but I think it'd be worth it for the performance gain and callback flexibility.
(If this comment was disrespectful, please report it.)

 
3/1/2004 9:43:14 PM,

Great Job! 5 Globes. Just to make sure, you don't mind if i use this in my future apps do you? Thanks for sharing with us.
(If this comment was disrespectful, please report it.)

 
3/1/2004 10:14:00 PM

I'm still using the cSocket of Oleg Gdalevich. Please tell us what you have
improved? But at least great job.
Dirk
(If this comment was disrespectful, please report it.)

 
3/1/2004 11:04:14 PMEmiliano Scavuzzo

Paul Caton:
Thanks man, your code was the most brilliant piece of work I've ever seen.
(If this comment was disrespectful, please report it.)

 
3/1/2004 11:08:38 PMEmiliano Scavuzzo

Luke H.:
That's seems like a great idea, but the problem is that CSocketMaster is intended to mimic winsock and nothing more. But you can use my code and change it that way on your own project if you like.
(If this comment was disrespectful, please report it.)

 
3/1/2004 11:14:32 PMEmiliano Scavuzzo

Unknown:
You can use my code for whatever you want. You can add or remove code too if that's what you want.
(If this comment was disrespectful, please report it.)

 
3/1/2004 11:34:40 PMEmiliano Scavuzzo

Unknown:
Csocket by Oleg Gdalevich has many differences from CSocketMaster. Here are some of them:
1)It's not IDE safe
2)When you call Close method the socket may not be closed at the time this method returns.
3)If you decide not to accept an incoming connection the socket that was created before the ConnectionRequest was fired is never closed. The other peer thinks the connection is still up.
4) Some parts of the code has a faulty error handling.

Besides these, I can name hundreds of tiny things that make CSocket have a different behavior from winsock. I don't want to talk about CSocket any more cause people will think I'm talking about CSocketMaster.
(If this comment was disrespectful, please report it.)

 
3/2/2004 12:26:30 AMCodeClub

cSocket class is the best one!
(If this comment was disrespectful, please report it.)

 
3/2/2004 1:07:46 AMTechni Rei Myoko

*Checks voting log* Everyone say it with me, 'nice'.
(If this comment was disrespectful, please report it.)

 
3/2/2004 1:31:08 AMMasino Sinaga

LOL, everybody hates winsock control. Yup! Me too.
(If this comment was disrespectful, please report it.)

 
3/2/2004 1:35:42 AMMasino Sinaga

The only reason I love this class so much is because there is a way to clean up the memory in it. And it's IDE Safe too. 5 globes from me, of course.
(If this comment was disrespectful, please report it.)

 
3/2/2004 6:14:15 AMCodeClub

in CSocketMaster.cls, line "Case vbArray + vbByte", change the its code to "arrData() = data" for a direct and proper way, because a loop change with Strconv(x,Unicode) will failed with double-byte characters such as simplified chinese.
(If this comment was disrespectful, please report it.)

 
3/2/2004 6:17:32 AMCodeClub

your website http://www.geocities.com/anshoku/ does not work
(If this comment was disrespectful, please report it.)

 
3/2/2004 8:59:25 AM

It is Good
(If this comment was disrespectful, please report it.)

 
3/2/2004 10:13:14 AMDmytro

amazing, 5 from me!!!
(If this comment was disrespectful, please report it.)

 
3/2/2004 10:55:09 AM

Hmmm... I did not go into it verry deep but it looks like that if you use this in a server that it can only handle one connection at a time. Is that right or am I missing something? Why are you closing the socket when there is a connection request?

Some time ago I posted a verry similar project here on PSC. The idea is the same but the structure is different. It does also use the Pault Canton subclass code. Maybe it can be of anny use:

http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=39939&ln gWId=1

(If this comment was disrespectful, please report it.)

 
3/2/2004 7:03:49 PMEmiliano Scavuzzo

CodeClub:
Thanks for the bug report. I'll try to fix all bugs reported on next version.
(If this comment was disrespectful, please report it.)

 
3/2/2004 7:08:55 PMEmiliano Scavuzzo

Unknown:
A server socket can handle as many connections as your computer can handle. When a new connection request is received the socket created only is closed if the user (you) doen't accept it using Accept method.
(If this comment was disrespectful, please report it.)

 
3/2/2004 8:24:15 PMXomni Networks

excellent quite excellent. enough to make me delete the mswinsock.ocx all together :-D
(If this comment was disrespectful, please report it.)

 
3/3/2004 6:28:06 AMMarcelo Luiz Altafin

Congratulations. Excellent code.

(If this comment was disrespectful, please report it.)

 
3/4/2004 3:17:01 AMkorejwa

Very Impressive! However, I agree with Luke H's general idea of having the ability to access multiple sockets, and adding an Index to each of the procedures and events to identify them. Although you claim you are just trying to mimic the winsock control, the fact that you don't have to put it on a form solves a HUGE class of limitations over using a control ... perhaps more than you know. A CSocket Class capable of an arbritrary number of connections would make that worthless Winsock control completely obsolete. I've been working on a similar Class that controls a dozen serial ports. Believe me, controlling multiple sockets from one Class is a worthwhile project, and would solve every 'socket' need imaginable. 5 from me, and congrats for winning the 'code of the month' award.
(If this comment was disrespectful, please report it.)

 
3/7/2004 6:54:35 PM

So can I just remove the winsocks, add this, and name them winsock1, winsock2, et cetera??? :)
(If this comment was disrespectful, please report it.)

 
3/7/2004 6:55:42 PM

Another thing.... what about error handling? Does it give the same errors? Some of my error catching is based on the errors returned, specifically Winsock Error 10054.
(If this comment was disrespectful, please report it.)

 
3/9/2004 12:41:55 AM

Jarry's post got me thinking ...

So... I tested.
I queried a master list of an average of 600 servers.

I gauged the effectiveness of winsock & csocketmaster based on the successful udp replies.


UDP SERVER REPLIES:
winsock / csocketmaster:
555 servers replied,388 replied.
551,401.
554,384.
Winsock's stuttered some while they were updating (1,2,3 40...100..110,111,112) while cSocketMaster was steady (1,2,3,4,5,6....300,301,302 etc) , but it was Winsock who was reliable on the responses...

Something is not right with the way it handles UDP?
Please fix this, I'd love to use it!
(If this comment was disrespectful, please report it.)

 
3/13/2004 2:52:54 AM

I'm the one who posted the example.

I can't show you my code becuase my example would require giving you access to 500 servers that I cannot give acess to.

But basically I sent a udp message to 500+ ips or so and waited for data to arrive (data_Arrival)
(If this comment was disrespectful, please report it.)

 
3/15/2004 2:22:55 AMsYNAPSE

i think i may have found a bug.. I am connected to the internet thru a LAN. So I have an internal IP address: 192.168.0.50. I made Socketmaster listen to a port and tried telnetting to 127.0.0.1. The connection is never accepted! BUT if i telnet 192.168.0.50 it works with no problems! So 127.0.0.1 or localhost does not seem to get to work.
(If this comment was disrespectful, please report it.)

 
3/17/2004 9:24:31 AMEmiliano Scavuzzo

sYNAPSE:
Thanks for the bug report. Make sure it's a bug using winsock control instead of CSocketMaster. If the problem is solved that means it really is a bug. Please post another message with the results.
(If this comment was disrespectful, please report it.)

 
3/19/2004 11:54:19 PMAlpha Binary

you should try sending/receiving chars with ascii above 200
btw do i have to attach the .asm file with the executable i made?
(If this comment was disrespectful, please report it.)

 
3/21/2004 12:26:38 AM

great code Can you email me at XPh0zE@Hotmail.com im coding my own language interpreter and I was about to use winsock but that would mean attach the .ocx file which makes it not as stable (if ocx deleted then its a problem..). I was wondering if I could use your classes in there.

Please give E-Mail me so we can talk about it thanks

Alias: Endra
E-Mail: XPh0zE@Hotmail.com
Aim: ENDRA123

Thx again
(If this comment was disrespectful, please report it.)

 
3/21/2004 12:27:43 AM

<give E-Mail me so we can talk about it
thanks>>

typo meant please email me :p thx again 5 globes from me

(If this comment was disrespectful, please report it.)

 
3/24/2004 4:41:37 AMEmiliano Scavuzzo

Alpha Binary:
What do you mean?
(If this comment was disrespectful, please report it.)

 
3/24/2004 4:45:28 AMEmiliano Scavuzzo

XPh0zE:
Dude, you can do whatever you want with this code.
(If this comment was disrespectful, please report it.)

 
3/24/2004 1:15:17 PMBill Peek

Excelent. This makes one less oportunity (problem) to deal with. Keep up the good work!
(If this comment was disrespectful, please report it.)

 
3/25/2004 3:19:54 AM

Why does it drop 20-40% more UDP packets than Winsock? :(

Please fix this!
(If this comment was disrespectful, please report it.)

 
3/26/2004 7:24:05 AM

Emilio... first of all congratulations with this nice piece of coding. I could replace the winsock ocx in only a few minutes.

But it does not seem to work on my win98 system, even some people with XP have troubles.
I make a connection with a proxy, but it does not connect...
Maybe it's due to an older version of the sck32 dll you use.

On my xp system it works like a charm, i had a little tool that used multiple threads and now it seems even more stable with it.
I can't thank you enough.

Greets,
Cb
(If this comment was disrespectful, please report it.)

 
3/26/2004 7:24:51 AM

sorry not Emilio, but Emiliano.
(If this comment was disrespectful, please report it.)

 
3/26/2004 11:23:14 PM

Awesome Code =)

Just one thing I cant figure out: how would I go about using Index's?

thx

(If this comment was disrespectful, please report it.)

 
3/28/2004 3:06:44 AM

omg man i love you.. this is great, thank you sooo much :)
(If this comment was disrespectful, please report it.)

 
3/28/2004 7:23:18 PMRana Hossain

BUG: First congratulation for such a nice code. I have a small SMTP class to send Mail. I noticed the bug when I tried to send a 2nd mail. On SMTP return 221 (from data arriaval), I try to close the socket - but that doesn't close it down/and return the event (FD_Close doesn't get returned). I have changed the events to match CSocket. When I use CSocket, that works fine. Any idea?

(If this comment was disrespectful, please report it.)

 
3/28/2004 11:37:03 PMEmiliano Scavuzzo

Unknown:
I've just tested CSocketMaster on win98 SE with no problems. You should get a 10092 error if your winsock file doesn't suppor 1.1 version. Maybe your file is corrupted.
(If this comment was disrespectful, please report it.)

 
3/28/2004 11:50:13 PMEmiliano Scavuzzo

Rana Hossain:
Mmm, if I understand correctly you're trying to close the socket when you get a 221 SMTP good bye code. You say the socket doesn't close? That's weird. I would need to see the debug logs or some sample code to help you.
(If this comment was disrespectful, please report it.)

 
3/31/2004 12:25:01 AMEmiliano Scavuzzo

I've tested CSocketMaster on a LAN seeking for bugs and these were the results:

BUG) If you bind socket to your lan IP and try to connect to 127.0.0.1 or localhost the connection is rejected
RESULT) This appear to be normal behavior. The same happens using winsock.

BUG) CM takes to long to resolve hosts.
RESULT) I had no problems to solve local or internet hosts.

BUG) CM drops more UDP packets than winsock.
RESULT) I had no problems with that.

If you have a code that presents any of these bugs, please send it to me so I can fix it.
(If this comment was disrespectful, please report it.)

 
4/2/2004 4:06:24 AM^_^

wow!
(If this comment was disrespectful, please report it.)

 
4/2/2004 12:44:47 PMMax Powers

I ran this thing through Project Analyzer (http://www.aivosto.com/project/project.html) and it found some errors. Nothing big but the code could go through some optimization. Besides that I use this code in my own programs now and I havent noticed much anything except I have to connect to 192.168.1.101 instead of 127.0.0.1
(If this comment was disrespectful, please report it.)

 
4/2/2004 12:46:06 PMMax Powers

Also when im using the Socket control and on form load I have sckServer.Listen set then after I end it through the IDE I get the Address in Use error.
(If this comment was disrespectful, please report it.)

 
4/3/2004 3:01:26 AMEmiliano Scavuzzo

Max Powers:
Like I said before this thing of listening to your LAN IP and not being able to connect to 127.0.0.1 seems to be normal. I tested with Winsock control and it does the same thing.
Please, post your bug code so I can fix it.
(If this comment was disrespectful, please report it.)

 
4/5/2004 6:06:19 PMandymacp

I've set up a forum for to discuss this class, would be good to have a discussion,
http://s6.invisionfree.com/CsocketMaster/index.php?act=idx

(If this comment was disrespectful, please report it.)

 
4/6/2004 11:26:55 PM

hey this is endra again im not sure if this has been posted before but i think there may have been a bug/coding error in the classes.. I was writing a Identd server and i listened on port 113, then stopped the program (in the ide), and when I played again, I got a 10048 error (Address already in use).. its being traced back to be used by VB6.EXE (the only vb6 process I have is that one). The status of it was CLOSE_WAIT, the line where the error pointed to was:

Err.Raise lngErrorCode, "CSocketMaster.BindInternal", GetErrorDescription(lngErrorCode)

Line 803 of the class.. in the BindInternal() function.

Let me know if im doing something wrong because shouldnt all connections used by the program be closed when the program is Stopped (stop button not closing the vb IDE). Thx
(If this comment was disrespectful, please report it.)

 
4/8/2004 2:43:39 AMEmiliano Scavuzzo

Endra:
Yes, this is normal. When you hit the end button the sockets are not closed by CSM. Thanks to remind me this cause I think I can easily fix this for the next version.
(If this comment was disrespectful, please report it.)

 
4/8/2004 4:08:21 PM

Emiliano, primero q todo me parece exlente tu codigo, pero tengo algunas dudas:
Hace un tiempo hice una pequeña aplicacion para enviar mail usando el control winsock, pero al intentarlo con tu clase no consigo ni siquiera conectarme al servidor (smtp).
En el debug me aparece lo siguiente:

OK Subclass memory allocated at: 6762684
OK Winsock service initiated
OK Created socket: 448
Winsock buffer size for sends: 8192
Winsock buffer size for receives: 8192
OK Created socket collection
OK Created winsock message window 3192
OK Registered events from socket 448
STATE: sckResolvingHost
Resolving host mx4.hotmail.com with handle 15
STATE: sckHostResolved
OK Bind HOST: 192.168.0.104 PORT: 1230
OK Connecting to: mx4.hotmail.com
STATE: sckConnecting

Estoy en una red local no se si será ese el problema.

Tambien me interesaria saber si tienes mas ejemplos, ya que soy algo nuevo con el winsock.
(If this comment was disrespectful, please report it.)

 
4/9/2004 11:11:58 PMEmiliano Scavuzzo

Gracias por tu comentario.
¿Eso es todo lo que muestra el debug? ¿No hay nada más? ¿Devuelve algún error?
Prueba esto:
1)¿Estás seguro que te estás conectando al puerto correcto? Tendrías que conectarte al puerto 25 para acceder al SMTP.
2)Intenta usar el control winsock para ver si el problema se soluciona. Si no se soluciona significa que el problema está en tu código.
3) Prueba si te funciona el ejemplo 1, el simple TCP chat y cuentame los resultados.
(If this comment was disrespectful, please report it.)

 
4/10/2004 7:22:45 PM

Gracias por tu respuesta.
Ahora me funciona, solo era q el servidor smtp no estaba funcionando.
Todo funciona perfecto.

(If this comment was disrespectful, please report it.)

 
4/11/2004 8:00:19 PM

Emiliano soy yo denuevo, tengo una pregunta:

Necesito enviar un string, el problema es q es demasiado grande, entoces me lo divide en paquetes de 8192 bytes. Mi pregunta es ¿como puedo hacer para unir esos paquetes en una sola variable cuando ocurra el evento DataArrival?

Espero haber sido claro y tu pronta respuesta.

Gracias de antemano
(If this comment was disrespectful, please report it.)

 
4/11/2004 10:00:37 PMTimothy Marin

Hi im having a bit of a problem with this.. ive been using CSocket for a while.. it has a ton of bugs. CSocketMaster seems to be much better. but i am having some troubles. it seems that sometimes the class is waiting for all data to be sent from a packet before calling the OnDataArrival event. I may be wrong on the problem, but it freezes up sometimes and consumes a large amount of memory(about 120 MB in this case) and then seems to go back to normal after 30 seconds or so. If you have any idea on what could help this please respond to Timcrosoft@hotmail.com, I will try to create a program to recreate this problem.. i havnt Tested yet but with CSocket i had to remove the Resolve Host function from the UDP part for my app because it recieved over 1000 packets from varius address' in less than 10 seconds it froze up with the roslolving and removing it seemed to work well. I have yet to see if this is a problem with CSocketMaster but will keep you informed. I love this control 5 Globes
(If this comment was disrespectful, please report it.)

 
4/12/2004 10:28:19 PM

np, let me know when you release the next version. Also if you can add a way to index the class, not the control, it would be awesome =)
Once again awesome code.

-Endra
(If this comment was disrespectful, please report it.)

 
4/13/2004 9:40:37 PMTimothy Marin

-Endra
and anyone else who requested info on indexing the class.
http://www.pscode.com/vb/scripts/ShowCode.asp?txtCodeId=53077&lngWId=1
is a basic server using CSocketMaster.

Tim-
(If this comment was disrespectful, please report it.)

 
4/13/2004 11:07:18 PM

Thanks
great code Tim =-]

-Endra
(If this comment was disrespectful, please report it.)

 
4/20/2004 10:03:18 AMThushan Fernando

great work, just so everyone knows, this is plug and playable but change your Close events to CloseSck and know that theres no 'ErrorConstants' implemented in this yet(future?)... but its certainly very nice work:D
(If this comment was disrespectful, please report it.)

 
4/20/2004 10:10:30 AMThushan Fernando

okay i'll email you the ErroRConstants enum you can add to the class in the morning...
(If this comment was disrespectful, please report it.)

 
4/22/2004 3:36:20 AM

Perfect, I hate using the .ocx. :P
(If this comment was disrespectful, please report it.)

 
4/25/2004 12:50:03 PMAnti-Geek

this is nice . but you still have a same general Errors As the original Winsock.ocx . you probly like ok what the error . the error is multi sockets . try this . make this ocx a multi socket then make winsock keep connecting to your multi server . your multi user server will error faster then the pope can get on his knees to kiss the ground
(If this comment was disrespectful, please report it.)

 
4/26/2004 4:59:10 AMJeffrey C. Tatum

Great Class. I never used CSocket, so I can't really compare the two. But CSocketMaster certainly is better than the winsock control. Two problems though.

One, it get's the local IP wrong. I'm behind a router, and unless it has the right local IP, I can hardly connect to anything. I had to go in and change that around to get it to work properly.

Two, sometimes it just won't disconnect from a server. I mainly use it for winsock aim/aol applications. Calling the CloseSck event does absolutely nothing. It keeps me connected to those services. Even when I completely stop the project, the names are still online. They don't actualy sign off till I actualy close Visual Basic.

Other than those problems, great code!
(If this comment was disrespectful, please report it.)

 
4/26/2004 11:59:35 PMk0nsl

Very nice code
(If this comment was disrespectful, please report it.)

 
4/30/2004 11:17:18 PMGaseosid

Cant describe it!
(If this comment was disrespectful, please report it.)

 
5/27/2004 4:53:24 AM

Hi Emiliano,
Like the others I think this is a great class for overcoming the inadequacies of Winsock and it is very easy to use.

My problem is that I cannot get it to work on a server.

I incorporated CSocket~Master into a .exe which I ran on my Windows 2000 Client PC and it worked fine, doing everything that I needed it to.

I then copied this .exe to a Windows 2000 Server and kept getting a lastDllError 10035 'Socket is non-blocking and the specified operation will block'.

I have looked around for solutions to this and the only ones I can find say that you need a pause then to try and connect again. I tried this and could never make a connection.

Do you know what is wrong.

Thanks
(If this comment was disrespectful, please report it.)

 
5/27/2004 6:35:05 AM

Hi Emiliano,

Ignore my last message.

Since I sent it have been told that the server I am testing on has been upgraded from an NT4 to a Windows 2000 using the upgrade and not a clean install.

I ran my code on 2 other servers and it worked perfectly.

Sorry if I wasted any of your time.

Unfortunately for me, I've spent over a week on this.
(If this comment was disrespectful, please report it.)

 
6/4/2004 7:04:04 AMMichael D.

Hi, I implemented this instead of Winsock OCX - works FINE locally, doesnt do ANYTHING remotely - as UserControl or Class: I even tried connecting to my site on port 80 from the sampel chat project, still nothing : OK Bind HOST: 10.95.194.65 PORT: 3161
OK Connecting to: www.lfi.net
STATE: sckConnectingSTATE: sckError
(If this comment was disrespectful, please report it.)

 
6/5/2004 5:43:10 AMTony G

Great code, totally eliminates the learning curve. Thanks 5 globes
(If this comment was disrespectful, please report it.)

 
7/19/2004 4:05:25 PM

I'm switching all my code from the winsock control to this class. I love it!
(If this comment was disrespectful, please report it.)

 
7/28/2004 3:58:38 AM

There is a commented section in GetRemoteInfoFromSI(), but one of the lines is not commented:
strRemoteHost=
(If this comment was disrespectful, please report it.)

 
7/28/2004 4:00:19 AM

There is a commented section in GetRemoteInfoFromSI(), but one of the lines is not commented:
strRemoteHost=empty
This causes a 10047 error in VB when SendBufferedDataUDP is called again. I am guessing this variable should not be cleared here. Can you confirm this?
(If this comment was disrespectful, please report it.)

 
7/30/2004 8:25:43 AM

I have a small SMTP client to send mails and CSocketMaster can't send file attachments. It gets an error and closes the connection. Am I doing anything wrong? I don't have the same problem with WinSock control. Would appreciate any help. Thanks.
(If this comment was disrespectful, please report it.)

 
9/2/2004 2:39:02 PM

Hi All,

Have anyone tried using CSocket or CSocketMaster to transfer files such as bmp or gif? I tried many times and many ways but in vain. Winsock has no problem at all.

(If this comment was disrespectful, please report it.)

 
12/2/2004 2:37:25 AM

Great code, beautiful code, nice code, great comments in one word Congratulation
(If this comment was disrespectful, please report it.)

 
1/15/2005 6:34:20 AMDherar Z. AL-Rashoud

I like this code alot... but I have a question:

am I able to send files through CSocket?
not via URL... I mean like Peer to Peer
(If this comment was disrespectful, please report it.)

 
1/28/2005 3:42:30 PMNarayan Acosta

a very good code i was just doing something like this when .... this save my life
(If this comment was disrespectful, please report it.)

 
2/15/2005 12:50:41 PM

Hi, ive used your code in my projects as a replacement for winsock and it works great! i just encountered a few problems, most of the time, the state is not updated real time. Like when i connected it to a server then terminated the server after establishing connection, in the close event, socket does not close so i manually closed it thru code. if you dont close it manually, state remains at "Closing" .... if you'll try to reconnect to the server at this state, error will occur.
(If this comment was disrespectful, please report it.)

 
4/19/2005 2:15:56 PMHakavelli Pliz

Thanks for sharing, best winsock replacement i've come across - Excellent [5 Globes]
(If this comment was disrespectful, please report it.)

 
5/4/2005 1:50:34 PM

Just want to know if we can use this code freely or has some license limitation.
(If this comment was disrespectful, please report it.)

 
11/7/2005 12:06:06 PMRuss

It works great with talkclient.Protocol = sckUDPProtocol

but I can't make it work with talkclient.Protocol = sckTCPProtocol

I want to get away from UDP and use TCP but it won't work.

russ
(If this comment was disrespectful, please report it.)

 
11/27/2005 12:42:40 PMBololom

There is a big problem in this winsock replacement , it cannot be used to send files (Client/Server file transfere) (P2P), the files will be damaged coz the CSocketMaster transferes data to and from vbunicode
(If this comment was disrespectful, please report it.)

 
12/27/2005 1:40:22 PMJames Johnston

It transfers files just fine for me! And the data comes back in what ever form the server sends it in.

Great Job!!!

I did make one change that should be updated.

From:
Public Event Error(ByVal Number As Integer, ByVal Description As String, ByVal Source As String)

To:
Public Event Error(ByVal Number As Long, ByVal Description As String, ByVal Source As String)

For some reason I've been getting some error numbers back that are bigger than an integer and it was causing an overflow error. This change corrects that.
(If this comment was disrespectful, please report it.)

 
2/9/2006 5:58:50 AMFolo

this appears to be crashing on windows 2003 servers.
(If this comment was disrespectful, please report it.)

 
2/13/2006 2:55:47 AMrod

hello, i've tried using csocket master in a chat application but the server program that i've created unloads without any error after about 80 plus conenctions and without me triggering it (like unload me or end). i've tried to write a log file so i could know the function where the program ends but the program stops at different functions. the server is on a windows 2003 server. need your help guys. thanks.
(If this comment was disrespectful, please report it.)

 
2/13/2006 3:14:13 AMrod

sir can i ask what is the maximum connection that csocketmaster can provide?
(If this comment was disrespectful, please report it.)

 
5/4/2006 5:03:25 AMMilind Patil

Hello ,
I m using TCP protocol in VB winsock to connect Visual Basic client to Java Server.
Java Server Sends me data in the form of XML File. But sometimes i receive incomplete XML data . I also used "Doevents" in the "DataArrival" event of Winsock. But still sometimes i am getting incomplete Data.
Why it is so ?


Milind
(If this comment was disrespectful, please report it.)

 
6/8/2006 1:55:08 PMGuillermo R. Flook

but the same if it is at the same form.

I set it as TCP, and calls to connect event, with remoteport/ip specified.

Happened that works GREAT if the client/server is at same IP, but when you move that client to another PC in LAN, the TCP instance directly does NOT works NOTHING.

then, I removed the first instance replacing with a dll function to get the machine IP
so I erased all the first instance at all. (that was just 5 lines in the main form_load)

(If this comment was disrespectful, please report it.)

 
6/8/2006 1:56:02 PMGuillermo R. Flook

and miracle, the TCP instance works ok, and by that all the application works ok.


So, EVERYBODY DON'T MIX UDP and TCP

other thing, can be that to connects it gets log time like 3 or 4 seconds?




(If this comment was disrespectful, please report it.)

 
10/5/2006 9:57:38 AMg0liath

Similar to Rod's comment above - i've also experienced my CSocketMaster server unexpectedly terminating w/o notice while in use. Has anyone else experienced this and if so any workarounds or suggestions?
(If this comment was disrespectful, please report it.)

 
1/27/2007 2:36:54 PMAleppo

Yes, in Win2003 server environment the whole program crashes silently. This happens in subclassing module when calling

api_SetWindowLong(hwnd, GWL_WNDPROC, nAddrSubclass)

(If this comment was disrespectful, please report it.)

 
3/25/2007 10:07:04 AMLadyLuck

Hi. love the easy code implementation into a project and no dependencies to worry about. good job thanks.
Also, i have been trying to find some info on setting up a server/multiple clients project in visual basic 6 that can be run on the same form and no need to have 2 seperate instances of the server and client. I've found a little in regards to making the sockets into arrays and not much else though.
The reason i'd like to have it working this way is so that when a server logs off the network, the rest of the connected clients dont get disconnected from the network as well. Maybe if there is some way that the function of the server could be switched to the next connected client?
Is there a way to do this, or a good source on what i'm asking that i haven't come across yet? Thanks.
(If this comment was disrespectful, please report it.)

 
5/26/2007 8:02:25 AMPuddy Davidson

I dont think anyone is watching this submission anymore, but i will state a big difference between this mock of mswinsock ...
This control will bug out and close the connection if it gets slapped on the wrist by certain firewalls, where as the normal winsock control will soldier through it.

To test this - Add a normal winsock and a cmaster winsock and code them both to connect to any server
connect them and see what happens(whilst running kaspersky intenet security)

normal winsock will send the data, cmaster will not.
If anyone knows a fix for this then plz make comment of it.

It is a super control Emiliano and it deserves more globes than I can give.
(If this comment was disrespectful, please report it.)

 
8/18/2007 1:01:29 PMJason Newland

it is a good implimentation and a better version of original cSocket (that thing had the nasty tendancy of not being able to connect straight after it was closed). One thing would have been good to impliment in this would be that of multi-threading. Other than that, 5 globes from me.
(If this comment was disrespectful, please report it.)

 
8/28/2007 12:17:14 PM

good, thank you so much
(If this comment was disrespectful, please report it.)

 
9/22/2007 12:03:19 PMCarlos

I don't know why but csocketmaster fails in IsAcceptRegistered function, maybe a windows actualization because old versions of my software also fails in my actual system (and it works the last month)
I change the function to this:
Public Function IsAcceptRegistered(ByVal lngSocket As Long) As Boolean
On Error GoTo Error_Handler
Dim oTemp As CSocketMaster
Dim bAccepted As Boolean
WriteLog "IsAcceptRegistered"
For Each oTemp In m_colAcceptList
If oTemp.SocketHandle = lngSocket Then
bAccepted = True
Exit For
End If
Next
IsAcceptRegistered = bAccepted
'
Exit Function
'
Error_Handler:
IsAcceptRegistered = False
End Function

(If this comment was disrespectful, please report it.)

 
6/25/2008 5:53:02 AMedid

Hi, great job, but...
Launch twice SimpleTCPChat.exe, set 2 differents Port number in Server forms and click Listen on both forms.
You'll have a "Address already in use" error... What's up?

(If this comment was disrespectful, please report it.)

 
3/15/2009 2:58:46 AMRenja_xx17

Thank's
(If this comment was disrespectful, please report it.)

 
5/17/2009 4:51:54 AMakatran

Great job, 5 globes from me too...
I have one problem though. Seems to me if you have more than one LAN interface, the class might not get the correct IP for local ip.
ex: One lan interface with 192.168.x.x and other lan with 169.x.x.x.
Gethostbyname returns the 169.x.x.x ip which is wrong of course as the gateway is on the 192.168.x.x interface.
What can I do besides to turn of the 169.x.x.x interface????
(If this comment was disrespectful, please report it.)

 
5/17/2009 5:21:48 AMakatran

My problem solved by setting the strLocalHost to ALLAddresses (0.0.0.0).

I changed the strLocalHost in CSocketMaster.GetLocalIP from strLocalHost = GetLocalHostName to strLocalHost = "0.0.0.0".
This way it determines automatically the correct IP for local ip, I think, or it set it to all IP!!!! I doesn't matter any way...

(If this comment was disrespectful, please report it.)

 
2/28/2010 11:35:10 AMBysmarck

i need to use this wonderful class in windows vista,do somebody know a equivalent class ?
(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.