Results 1 to 10 of 15

Thread: Sockets unit in Lazarus

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Bleh.. had a copy/paste error in the server. Sorry about that; that code is likely not bug-free, I just syntax-checked it to be sure the compiler wouldn't barf on it. It is one of my personal rules about providing examples. I edited the server code to fix that bug. Try it now and see if it works. There may be an issue with the way I am handling the string buffer, but it should work.

  2. #2
    Yeah it doesn't look like its sending the string buffer to the client. When I run the server it says this:

    Waiting for Connect from Client, run now sock_cli in an other tty
    Server : Accept : 10014

    Then it instantly finishes, not sending any buffers or anything. The client runs and simply says:

    Client : Connect : 10061

    Then finishes. *boggle*

  3. #3
    Just a general tip for all who want to do network programming: Install wireshark and learn how to use it. It allows you to monitor your network traffic with great detail.

    During my computer networks course at university, I had to do some programming assignments and wireshark helped me ALOT there.
    Coders rule nr 1: Face ur bugz.. dont cage them with code, kill'em with ur cursor.

  4. #4
    Chronozphere: Yeah, a sniffer can be helpful once you get to where you are exchanging traffic and are having issues with sending/receiving.

    Nick: It looks like the server socket address wasn't being set in the server. Those numbers you see are Winsock errors, and you can look them up in the header files or on the internet (google "winsock errors"). 10014 is "Bad Address" on the Accept, and indeed, the server code set the address for the server socket to 0 (again, that example code in the FP help is awful). 10061 is "Connection refused", which is exactly the error you should get if the server isn't running.

    I also went ahead and tested it myself this time, and the updated version of both the client and server works OK. So now you can ask questions about what it is doing, if you like.

  5. #5
    It works! My god it works! =) Very good work, you guys are awesome. I will reply here if I run into any more problems while implementing it into my own programs. Thank you!

  6. #6
    One baby step further: how can I make the server not shut off when a client connects? I'd like to have a server always running while clients connect and send different buffers to the server. Not sure how difficult this would be to do =] I tried to figure it out but ended up making the server crash lol

  7. #7
    Well, realize that these examples are real good for demonstrating the basics of socket / network programming. However, turning them into something practical will be a long road indeed.

    The first thing you need to do is understand what is going on and why. What the various socket functions are doing, what the contents of the data structures are, and what order you need to use to do any particular thing.

    Complex client/server network apps are also often multi-threaded, which throws a-whole-nother dimension of complexity into the mix, but we can get into that later.

    So, let's start with getting you real familiar with what is going on with the examples, then we can step up to more complex functionality when you're ready. Study the examples, and read a bit through the (windows or linux) socket documentation; you can find both on the internet with a simple google search on Winsock (the MSDN documentation is best) or unix sockets. Bookmark these resources, because you will be referencing them often in development.
    Last edited by Murmandamus; 05-03-2011 at 06:45 PM. Reason: typo

Tags for this Thread

Bookmarks

Posting Permissions

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