Results 1 to 12 of 12

Thread: Sockets

  1. #1

    Thread Starter
    Fanatic Member LITHIA's Avatar
    Join Date
    Dec 2002
    Location
    UK, England
    Posts
    575

    Question Sockets

    Hi,

    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:
    1. Dim sServer As New Socket(AddressFamily.InterNetwork, _
    2.    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.

    Thanks very much

  2. #2
    Frenzied Member Mike Hildner's Avatar
    Join Date
    Jul 2002
    Location
    Des Moines, NM
    Posts
    1,690
    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.

    Have fun,
    Mike

  3. #3

    Thread Starter
    Fanatic Member LITHIA's Avatar
    Join Date
    Dec 2002
    Location
    UK, England
    Posts
    575
    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!

  4. #4
    Frenzied Member Mike Hildner's Avatar
    Join Date
    Jul 2002
    Location
    Des Moines, NM
    Posts
    1,690
    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.

  5. #5

    Thread Starter
    Fanatic Member LITHIA's Avatar
    Join Date
    Dec 2002
    Location
    UK, England
    Posts
    575
    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
    Attached Files Attached Files

  6. #6
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    Look at the constructors..
    \m/\m/

  7. #7

    Thread Starter
    Fanatic Member LITHIA's Avatar
    Join Date
    Dec 2002
    Location
    UK, England
    Posts
    575
    sorry, i dont understand what you mean

  8. #8
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985
    Originally posted by LITHIA
    sorry, i dont understand what you mean
    A contructor is what is run when a class is created

  9. #9
    Member
    Join Date
    May 2003
    Posts
    58
    Here you'll find somewhere to start

    http://www.vbforums.com/showthread.p...hreadid=262524

  10. #10
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    I think you should buy a book about how VB.NET works, constructors is one of the topics the book will cover for sure
    \m/\m/

  11. #11
    New Member
    Join Date
    Jan 2004
    Posts
    2
    Well, I tried to get this working like the winsock ocx, and I get this:


    No connection could be made because the target machine actively refused it


    What exactly does this mean?


    edit: I did some research, apparantly this error occurs when you have no server, but I do.

    I have a solution with 2 projects, one of them is listening (I even have a label with the state updating every 100 ms.

    The other connects to the localhost using "localhost" and "127.0.0.1".

    No worky
    Last edited by RoxSox; Jan 14th, 2004 at 02:54 AM.

  12. #12
    Frenzied Member Mike Hildner's Avatar
    Join Date
    Jul 2002
    Location
    Des Moines, NM
    Posts
    1,690
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width