Thread: TCP to HTTP connection (no mysql required)

Page 1 of 4 123 ... LastLast
Results 1 to 10 of 39
  1. #1 TCP to HTTP connection (no mysql required) 
    Registered Member

    Join Date
    Aug 2008
    Age
    31
    Posts
    774
    Thanks given
    97
    Thanks received
    131
    Rep Power
    328
    Other-wise known as "SWSocket" connections.
    Most servers would use MySQL or a database for this. Using cron jobs.

    What is this?
    This is basically a way to connect to a HTTP socket type.

    Why would we want to do this?
    You can make many things from your website if you have this. You can execute commands via the socket, you can send items etc whatnot.

    How do i use?

    You first have to make a web function.

    Code:
    function SendMUSData($data){
    
    $mus_ip = localhost;
    $mus_port = 30;
    
    if(!is_numeric($mus_port)){ echo "<b>System Error</b><br />Invalid MUS Port!"; exit; }
    
    $sock = socket_create(AF_INET, SOCK_STREAM, getprotobyname('tcp'));
    socket_connect($sock, $mus_ip, $mus_port);
    
        if(!is_resource($sock)){
            return false;
        } else {
            socket_send($sock, $data, strlen($data), MSG_DONTROUTE);
            return true;
        }
        
    socket_close($sock);
    }
    usage: SendMUSData(CODE_HERE);



    Then you will need to add a MUS socket server to your runescape private emulator/server.

    Code:
    /************************************************\
     * ############################################ *
     * ##          RuneScape C# Emuator          ## *
     * ############################################ *
     * ##     Copyright (c) 2006 - 2009 AJ R     ## *
     * ## http://theajp.com/ <[email protected]> ## *
     * ############################################ *
    \************************************************/
    using System;
    using System.Net;
    using System.Net.Sockets;
    using System.Collections.Generic;
    using System.Collections;
    
    using RuneScape;
    
    namespace RuneScape.Net
    {
        /// <summary>
        /// Asynchronous socket server for the MUS connections.
        /// </summary>
        public class musSocket
        {
            private static Socket socketHandler;
            private static int _Port;
            private static string _musHost;
            /// <summary> 
            /// Initializes the socket listener for MUS connections and starts listening. 
            /// </summary> 
            /// <param name="bindPort">The port where the socket listener should be bound to.</param> 
            /// <remarks></remarks> 
            internal static bool Init(int bindPort, string musHost)
            {
                _Port = bindPort;
                _musHost = musHost;
                socketHandler = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
    
                Logger.WriteLine("Starting up asynchronous socket server for MUS connections for port " + bindPort + "...");
                try
                {
                    socketHandler.Bind(new IPEndPoint(IPAddress.Any, bindPort));
                    socketHandler.Listen(25);
                    socketHandler.BeginAccept(new AsyncCallback(connectionRequest), socketHandler);
    
                    Logger.WriteLine("Asynchronous socket server for MUS connections running on port " + bindPort);
                    Logger.WriteLine("Listening for MUS connections from " + musHost);
                    return true;
                }
    
                catch
                {
                    Logger.WriteError("Error while setting up asynchronous socket server for MUS connections on port " + bindPort);
                    Logger.WriteError("Port " + bindPort + " could be invalid or in use already.");
                    return false;
                }
            }
            private static void connectionRequest(IAsyncResult iAr)
            {
                Socket newSocket = ((Socket)iAr.AsyncState).EndAccept(iAr);
                if (newSocket.RemoteEndPoint.ToString().Split(':')[0] != _musHost)
                {
                    newSocket.Close();
                    return;
                }
    
                musConnection newConnection = new musConnection(newSocket);
                socketHandler.BeginAccept(new AsyncCallback(connectionRequest), socketHandler);
            }
            /// <summary>
            /// Represents an asynchronous, one time usage, socket connection between the emulator and HoloCMS, used for various live updates between site & server.
            /// </summary>
            private class musConnection
            {
                private Socket Connector;
                private byte[] dataBuffer = new byte[10001];
                /// <summary>
                /// Initializes the musConnection and listens for one single packet, processes it and closes the connection. On any error, the connection is closed.
                /// </summary>
                /// <param name="Connector">The socket of the musConnection.</param>
                internal musConnection(Socket Connector)
                {
                    this.Connector = Connector;
                    Connector.BeginReceive(dataBuffer, 0, dataBuffer.Length, SocketFlags.None, new AsyncCallback(dataArrival), null);
                }
                /// <summary>
                /// Called when a packet is received, the packet will be processed and the connection will be closed (after processing packet) in all cases. No errors will be thrown.
                /// </summary>
                /// <param name="iAr"></param>
                private void dataArrival(IAsyncResult iAr)
                {
                    try
                    {
                        int bytesReceived = Connector.EndReceive(iAr);
                        string Data = System.Text.Encoding.ASCII.GetString(dataBuffer, 0, bytesReceived);
    
                        string musHeader = Data.Substring(0, 4);
                        string[] musData = Data.Substring(4).Split(Convert.ToChar(2));
                        Logger.WriteLine("DATA: " + Data);
                        #region MUS trigger commands
                        // Unsafe code, but on any error it jumps to the catch block & disconnects the socket
                        switch (musHeader)
                        {
                            case "ITEM":
                                {
                                    int mUserId = int.Parse(musData[0]);
                                    int mItemId = int.Parse(musData[1]);
                                    int mItemAmt = int.Parse(musData[2]);
                                         JoltEnvironment.GetRuneScape().GetEngine().GetPlayerSession().GetItems().AddItem(mUserId, mItemId, mItemAmt)
                                    break;
                                }
                        }
                        #endregion
                    }
                    catch { }
                    finally { killConnection(); }
                }
                /// <summary>
                /// Closes the connection and destroys the object.
                /// </summary>
                private void killConnection()
                {
                    try { Connector.Close(); }
                    catch { }
                }
            }
        }
    }
    Usage to execute the case:
    SendMUSData('ITEM' . USERID . ITEMID . ITEMAMT);

    Template:
    Code:
                            case "ITEM":
                                {
                                    int mUserId = int.Parse(musData[0]);
                                    int mItemId = int.Parse(musData[1]);
                                    int mItemAmt = int.Parse(musData[2]);
                                         JoltEnvironment.GetRuneScape().GetEngine().GetPlayerSession().GetItems().AddItem(mUserId, mItemId, mItemAmt)
                                    break;
                                }
    Reply With Quote  
     

  2. #2  
    Doctor p - Sweet Shop

    Join Date
    Apr 2007
    Age
    31
    Posts
    6,835
    Thanks given
    150
    Thanks received
    584
    Rep Power
    2595
    nice, but really stop releasing c# stuff, nobody needs it, nobody wants it

    Reply With Quote  
     

  3. #3  
    eclipses
    Guest
    Quote Originally Posted by Nathan View Post
    nice, but really stop releasing c# stuff, nobody needs it, nobody wants it
    if you weren't a complete retard you could read the source and write a java implementation of it.
    Reply With Quote  
     

  4. #4  
    Doctor p - Sweet Shop

    Join Date
    Apr 2007
    Age
    31
    Posts
    6,835
    Thanks given
    150
    Thanks received
    584
    Rep Power
    2595
    Quote Originally Posted by eclipses View Post
    if you weren't a complete retard you could read the source and write a java implementation of it.
    being a retard has nothing to do with being able to read C#, if you didn't learn it then you simply can't read it

    Reply With Quote  
     

  5. #5  
    Registered Member thiefmn6092's Avatar
    Join Date
    Dec 2006
    Age
    24
    Posts
    2
    Thanks given
    26
    Thanks received
    389
    Rep Power
    0
    hey, great job TheAJ, be careful with MSG_DONTROUTE, though.
    https://twitter.com/********s1

    If you are a starter and want to learn rsps coding, i think that the server that fits most of your requests is deathlypvpz.
    I know some stone heads will flame and say its shit, i completely agree buy deathlypvpz is the best thing to start with.
    And you must do some Java courses in codecademy to improve yourself.
    Reply With Quote  
     

  6. #6  
    Registered Member Paketa's Avatar
    Join Date
    Oct 2007
    Posts
    2,681
    Thanks given
    17
    Thanks received
    82
    Rep Power
    680
    Good job. I really want to make a C# server Any idea where I can learn?
    Reply With Quote  
     

  7. #7  
    Doctor p - Sweet Shop

    Join Date
    Apr 2007
    Age
    31
    Posts
    6,835
    Thanks given
    150
    Thanks received
    584
    Rep Power
    2595
    Quote Originally Posted by Vigan20 View Post
    Good job. I really want to make a C# server Any idea where I can learn?
    google?

    Reply With Quote  
     

  8. #8  
    Renown Programmer
    veer's Avatar
    Join Date
    Nov 2007
    Posts
    3,746
    Thanks given
    354
    Thanks received
    1,370
    Rep Power
    3032
    what the fuck
    Reply With Quote  
     

  9. #9  
    Registered Member

    Join Date
    Aug 2008
    Age
    31
    Posts
    774
    Thanks given
    97
    Thanks received
    131
    Rep Power
    328
    Quote Originally Posted by Vigan20 View Post
    Good job. I really want to make a C# server Any idea where I can learn?
    I'm currently learning too.
    Just got into advanced Marshals

    I basically learn from the MSDN manual, searching via Google and e(lectronic)Books.
    Reply With Quote  
     

  10. #10  
    Registered Member

    Join Date
    Feb 2007
    Posts
    1,005
    Thanks given
    2
    Thanks received
    17
    Rep Power
    93
    Quote Originally Posted by Vigan20 View Post
    Good job. I really want to make a C# server Any idea where I can learn?
    C# is pretty close to Java, not many things are different.
    So if you know java, you know pretty much about C#
    -Removed

    Advertising is not allowed.
    Reply With Quote  
     

Page 1 of 4 123 ... LastLast

Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

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