Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #////////////////////////////////////////////////
- """
- Here I imported lots of different modules.
- """
- #/////////////////////////////////////////////////
- from Tkinter import * #Used to create the GUI
- from ScrolledText import ScrolledText #Used to create the Scrolled Text
- import socket #Used to create the server
- import sys #Used for exiting in case of issue
- from thread import * #Creates threading capabilities.
- #////////////////////////////////////////////////
- """
- This class (CHANGE NEEDED HERE) is used to define the socket.
- It creates the server, and has a send_cmd method
- which is called upon by the Tkinter class
- Application
- """
- #/////////////////////////////////////////////////
- BUFFER = 1024
- import socket
- import sys
- HOST = '' # Symbolic name meaning all available interfaces
- PORT = 8888 # Arbitrary non-privileged port
- s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- print 'Socket created'
- try:
- s.bind((HOST, PORT))
- except socket.error , msg:
- print 'Bind failed. Error Code : ' + str(msg[0]) + ' Message ' + msg[1]
- sys.exit()
- print 'Socket bind complete'
- s.listen(10)
- print 'Socket now listening'
- def serverloop(s):
- while True:
- global conn
- conn, addr = s.accept()
- print "Connected with", addr
- def RECEIVE(BUFFER):
- try:
- #Sending message to connected client
- #This only takes strings (words
- conn.recv(BUFFER)
- except Exception:
- import traceback
- print traceback.format_exc()
- def send_msg(conn):
- #Send some data to the remote server
- my_message = raw_input(">>>")
- #set the whole string
- conn.sendall(my_message)
- def main():
- start_new_thread(serverloop, (s, ))
- RECEIVE(conn, BUFFER)
- send_msg(conn)
- main()
- #////////////////////////////////////////////////
- """
- This class is used to hold the GUI stuff.
- It uses Tkinter and multiple frames to accomplish this task.
- It calls on commands from the Socket_Server class
- """
- #/////////////////////////////////////////////////
- """
- #Setup Stuff
- root = Tk()
- root.title("HoweIM Server GUI")
- #make my screen dimensions work
- w = 500
- h = 1000
- root.geometry("500x1000")
- #Create the Main-Frame
- Hold_Frame = Frame(root)
- Hold_Frame.grid()
- #Past Frame
- pastFrame = Frame(Hold_Frame, width = 100, height = 300)
- pastFrame.grid()
- pastText = ScrolledText(pastFrame, height = 30,
- width = 50,
- #This line (state = DISABLED) means that the user cannot edit this textbox
- state = DISABLED,
- #This line (relief = GROOVE, bd = 5) tells Tkinter to make a groove aroudn the box, and the width of the border
- #Is now 5
- relief = GROOVE, bd = 5)
- pastText.grid(row = 1)
- #Message Frame
- messageFrame = Frame(Hold_Frame, width = 100, height = 100)
- messageFrame.grid()
- space = Label(messageFrame)
- space.grid()
- message = Text(messageFrame, height = 10, width = 50,
- relief = GROOVE, borderwidth = 5,)
- message.grid()
- send = Button (messageFrame, text = "Send",
- command = lambda: send_msg(s,message))
- send.grid(row = 1, column = 1, sticky = S)
- #Side Frame
- sideFrame = Frame(Hold_Frame)
- root.mainloop()
- """
- #The functions that you find from now on are commands for Buttons
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement