Kevin Ferm
Kevin Ferm

Reputation: 111

Python, Pygame Mastermind lib - Use server functions from the client

This is my server code:

from Mastermind import *
from time import gmtime, strftime
import globalv as g
from db import *

class Server(MastermindServerTCP):
    def __init__(self):
        MastermindServerTCP.__init__(self, 0.5,0.5,10.0)

    def serverAlert(self, msg="Test"):
        print(msg)

    def connectAlert(self, username):
        timestamp = strftime("%H:%M:%S", gmtime())
        print(username + " connected to the server at: '%s'" % timestamp)

if __name__ == '__main__':
    ....(Start server etc.)

What I want to do, that I don't really know how, is I want to be able to call the connectAlert() function from my client, which would be placed on a different computer. If it's not possible, what's the best way to achieve the same result?

Upvotes: 0

Views: 388

Answers (1)

furas
furas

Reputation: 143097

You can't call this function directly.

It works this way (pseudocode):

  1. client connect to server
  2. client send data to server: for example string "call connectAlert for me",
  3. server receive data
  4. server decide what to do: if data == "call connectAlert for me": connectAlert(..)
  5. server send result to client
  6. client receive result
  7. if client need more information from server go to 2.
  8. client disconnect

EDIT:

Looking for information about Mastermind library I found this code:

https://github.com/propra13-orga/gruppe75/tree/master/Dungeoncrawler

See chat_client.py (MastermindClientTCP) and chat_server.py (MastermindServerTCP)

Upvotes: 1

Related Questions