#1
  1. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2004
    Location
    There where the rabbits jump
    Posts
    556
    Rep Power
    11

    Sockets commucation between server and client


    Okay I tried to get some info on this:
    I asked Grim also

    Now I am trying to porgram a program that communictes with sockets.

    It has to be able to recieve and send at the same type a make input and print.

    How would I do this???
  2. #2
  3. Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Dec 2004
    Location
    Meriden, Connecticut
    Posts
    1,797
    Rep Power
    154
    I think I would know some ways of doing so. But could you go more into detail on what you want to do and why you want to do this so I get a better idea of your idea? So far It seems you want to send/receive data to and from sockets running through other programs. If this is so, zeroforce.net (under the Downloads page) has a Battle.net program, don't mind the fact that it's Battle.net, it does the same thing, called BGate. It is located under the Source Codes section under Visual Basic. If this is not it, once again, go into detail more.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2004
    Posts
    461
    Rep Power
    24
    thats pretty much the basics of sockets, i dunno if you know anything about sockets, from the sound of it you don't. If not then i think you should probably go find a good tutorial or a book, i personly liked "Foundations of Python Network programing" by John Goerzen.

    I am not trying to be rude but sockets is a huge domain of information. So its probably best that you start from the basics and move on to harder stuff. Also to cover some of the basics, a nice tutorial by Peyton McCullough called "Sockets in Python" is on the devshed tutorials page. You can get to it by: http://www.devshed.com/c/a/Python/Sockets-in-Python/

    Comments on this post

    • netytan agrees : Nice post, I agree completely!
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2004
    Location
    There where the rabbits jump
    Posts
    556
    Rep Power
    11
    well i just need a server and a client that can send and recieve stuff at the same time.
    I i dont wanna us other programs
  8. #5
  9. Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Dec 2004
    Location
    Meriden, Connecticut
    Posts
    1,797
    Rep Power
    154
    I never said you had to use another program. But it's great for learning from. The only problem is that it's written in Visual Basic 6, and I don't know if you know that language or not.
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2004
    Posts
    461
    Rep Power
    24
    jsut read the tutorial we gave you, also, it isn't just that simple. Well it can be, but that is very weak. That tutorial i gave you will take you step by step into how to make something like that. It will also help explain the concepts.
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2004
    Location
    There where the rabbits jump
    Posts
    556
    Rep Power
    11
    I already read it along time ago and I don't know visual basic...
    I understand how t odo stuff
    but the problem is to parallely run send and recv wich I dont understand
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2004
    Posts
    461
    Rep Power
    24
    well the onyl way you can run them at the same time is to either fork or thread the server and client. This is a pretty advanced topic and there are hole books just covering that hole thing.
  16. #9
  17. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2004
    Location
    There where the rabbits jump
    Posts
    556
    Rep Power
    11
    cork? and thread? them
  18. #10
  19. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2004
    Posts
    461
    Rep Power
    24
    DevShed has a good tutorial on threading, I would love to be able to show you a simple way to do this, but what you are asking is as wide as asking "how do i implement and use python?". I mean threading and sockets is a huge huge topic in programing, so like i said it would be best to pick up a book.

    but the tutorial is http://www.devshed.com/c/a/Python/Basic-Threading-in-Python/
  20. #11
  21. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2004
    Location
    There where the rabbits jump
    Posts
    556
    Rep Power
    11
    Okay thanks I think my mom is on the right way to buy me one:P
  22. #12
  23. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2004
    Location
    There where the rabbits jump
    Posts
    556
    Rep Power
    11

    Scripts


    Okay well I have done this...

    Server:
    Code:
    from socket import *
    
    address = "localhost", 9999
    
    class Server(object):
        def __init__(self):
            self.sock = socket(AF_INET, SOCK_STREAM)
            self.sock.bind(address)
            self.sock.listen(5)
    
            while True:
                mess, addr = self.sock.accept()
                print "Connected: ",addr
                while True:
                    print mess.recv(9999)
    
    S = Server()
    Client:
    Code:
    from socket import *
    
    class Client(object):
        def __init__(self):
            Hostname = raw_input("What is your contacts hostname?")
            
            self.sock = socket(AF_INET, SOCK_STREAM)
            self.sock.connect((Hostname,9999))
            while True:
                message = raw_input("Type something...")
                self.sock.sendall(message)
            self.sock.close()
            
    C = Client()
    And when I try to connect from the client

    Code:
    Traceback (most recent call last):
      File "F:\Programming\Comun\clientmartin.py", line 14, in ?
        C = Client()
      File "F:\Programming\Comun\clientmartin.py", line 8, in __init__
        self.sock.connect((Hostname,9999))
      File "<string>", line 1, in connect
    gaierror: (11001, 'getaddrinfo failed')
    comes.

    Do I need the Ip of the hostname and if which one the inside between modem and computer or the outside one modem and internet???
  24. #13
  25. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2003
    Posts
    624
    Rep Power
    34
    You need the external one (the internet side of the modem), but you also need (if it's a broadband router rather than a dialup modem) the router to forward port 9999 to the computer behind it running your server.
  26. #14
  27. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2004
    Location
    There where the rabbits jump
    Posts
    556
    Rep Power
    11
    How would I forward it

IMN logo majestic logo threadwatch logo seochat tools logo