1

I want to connect to a number of different sockets/webservices on the command line and send data back and forth in the standard output/input.

I have been doing this using a variety of different languages and approaches so far: System.Net.Sockets in C#, flash.net.sockets in Flash and java.net.sockets in Java, depending on the protocol being used by the socket and the language being used in the client example given by the companies who've written the sockets. I've had enough of moving from language to language to do this (using the provided client socket example in each case), and will probably all the clients to java.

In the meantime, I want a way to connect to a socket on the command line in windows, see what's return in the standard output, send text to the socket on the command line (or a very, very simple GUI) and see what's returned back. I don't need any extra functionality like a periodic ping to keep the socket alive or anything.

What tools can I do this on Windows with? I've tried opening a telnet session to the socket i.e. push.domain.com 1234, and also tried using Putty to connect also, to no avail.

I'm trying to emulate the way a flash client connects to this socket and sends and receives data:

theSocket.addEventListener(Event.CONNECT, connectHandler);  
theSocket.connect(theHost, thePort);
* * *
private function connectHandler(event:Event) : void
{ 
     if (theSocket.connected)
        {
            bytes = new ByteArray();
            bytes.writeByte(35);
            bytes.writeByte(1);
            bytes.writeByte(23);
            bytes.writeByte(7);
            bytes.writeUTFBytes(theTopic);
            bytes.writeByte(0);
            theSocket.writeBytes(bytes);
            theSocket.flush();
            theSocket.addEventListener(ProgressEvent.SOCKET_DATA, handshakeHandler);
             * * * 
private function handshakeHandler(event:ProgressEvent) : void
{
        var zero:int = 0;
        theSocket.removeEventListener(ProgressEvent.SOCKET_DATA, handshakeHandler);
        theConnectionTimer.stop();
        var bytes:* = new ByteArray();
        var counter:int = 0;
        theSocket.readUTFBytes(theSocket.bytesAvailable));

        var a:* = theSocket.readByte(); 
        var b:* = theSocket.readByte(); // the second byte should be 1????      
        var response:* = theSocket.readByte(); // this is the reponse identifier. . . ???
        theMessageSize = theSocket.readByte(); // is this byte the size??????

        switch(response)
        {
             case 100:
            {
                while ((zero = theSocket.readByte()) != 0)
                {
                   var temp = counter++;
                       bytes[temp] = _loc_5;
                };
                theClientID = bytes.toString();
                trace("The client ID is: " + theClientID);

How can I send the bytes values of 35, 1, 23, 7 and 0, as well as the value of the variable, Topic, to the socket using Hercules (or any other tool). Ideally, I'd like to connect with Hercules, send those bytes and the topic, and get something back containing the clientID like in the code. Although, I don't know if hercules will render the bytes in the response into text for me.

I'd appreciate any pointers at all on this.

Thanks.

2 Answers2

0

I was thinking in Hercules and searching for the website I found out that there's already an answer here in stackoverflow. I think it does what you need and more.

Community
  • 1
  • 1
pmoleri
  • 4,238
  • 1
  • 15
  • 25
0

Uhm, I'm nost sure I understood completely what you are asking, but I don't see why telnet could not help you in this case.

AndreiBogdan
  • 10,858
  • 13
  • 58
  • 106