I want to create 2 simple programs which can communicate with eachother, client and server.
I was able to do this really easily with Visual Basic 6 using the Winsock control, but now I have heard you should use Sockets in .NET
Can anyone help me get started on using Sockets, as I have no idea how to use them - reading about sockets in the msdn just explains information which is irrelevant to what i want - it included dns resolving, which i dont need - i just want a simple connect to certain ip, transmit some data and close; simple as it gets with winsock.
VB Code:
Dim sServer As New Socket(AddressFamily.InterNetwork, _
SocketType.Stream, ProtocolType.Tcp)
I have that so far, where the hell do I go now? Or is there a different way to start. I wish it was just as simple as before...
Is it possible to use winsock anyway? Im feeling these errors it may produce aren't going to bother me if to fix them requires learning how to use Sockets - way too much work just to make the foundations to a simple client/server app.
When I did my first socket app in .net, I was bummed at how difficult is seemed compared to just using winsock. Took me a few stabs at it, but finally got a reliable app - actually a service - that accepts multiple connections from clients, forward them to a server, then when a response is received, forwards it to the correct client.
This is all done using asynchronous method calls. I started from the examples provided in MSDN found under Using an Asynchronous Client Socket, Asynchronous Client Socket Example, and similar titles for the server piece.
I'm glad I learned it, because it seems real robust, plus was edifying as far as the asynchonous business goes.
I've seem some posts where people have made the own class that does what winsock does, maybe you could search and try out one of those.
BTW, the first time I tried to use the winsock control in my .net app, the IDE crashed and I had to re-register the .ocx again. That was enough for me as I needed to make a commercial app - and the recommended method is not to use winsock anyway.
If you're into a learning exercise, give it a go - I'm pretty sure I can help you out as I had to struggle through it myself.
thanks, i did find a class created, but i find theres a little bit of learning to understand how the class works, its here: http://www.vbforums.com/showthread.p...hlight=sockets bottom post, or direct link: http://www.vbforums.com/attachment.p...postid=1554696
It looks good, but im not completely sure how to get the hang of it. Maybe somone can help me please?
Thanks for the tip mike, ill have a look at the Asynchronous Client Socket Example at msdn, but i doubt i will make much sense of it hehe.
cya - if you got tips about that class, please share them or any other tips concearning sockets. thanks!
If you decide to go the asynchronous route, you can pretty much make two applications - one client and one server - directly from copying and pasting the code examples.
Ive changed my mind lol, I have decided to use a class I found, but I don't know how to use it...
Its kind of strange, the only thing I can seem to do is to do something with the eState. I don't know where you declare the IP, Port, when to tell it to connect, disconect, listen etc.
I have attached it to this post, please take a look! Thanks
That's a pretty common error. Seems to happen when you try to connect to a machine - you can find the machine, but nothing is listening on the port you're trying to connect to. Firewalls etc. can limit port access also.
I'd verify the listening port and the port to connect to are the same, then try a port scanner.