Socket TCL

Hello friends,

not so long ago, I discovered on the tcl scripts that can be executed on cisco devices and found it very exciting. So I got me a few books with basics of tcl and had some time now to study, now I want to explore more advanced topics, such as let's say client-server communication. I found examples and even a few explanations, but I just don't get it. Is there a nice guy here on this forum who could chew for me? Let's say for example I want to create a socket between client and server on one single router on another and I want the server and the client communicate via messages bidirectionaly (client sends a string then the server receives and prints to stdout and vice versa).

Server-side is something like:

proc OnConnectProcedure {channel clientaddr clientport} {}

puts 'connected $clientaddr ".

puts $channel ' Hello, customer.

Close $channel

}

Socket - server OnConnectProcedure 9990

vwait forever

and this server will wait for connection on port 9990, print "connected x.x.x.x" and send client message hello to the customer. Right?

What is on the other side?

Set the server x.x.x.x

the value sckt [socket $server 9990]

Gets $sock str

puts "server says: $str.

close $sockChan

But what about when a lot of questions come to mind... How messages should go the other way - from the client to the server, how and when can I use fileevent (readable, writable), fconfigure, synchronization option, when should I empty the channel? How and when should I wait for the expressions of folklore in the channel?

I am very grateful for any help and thank you in advance.

You can actually use examples directly to the communications server Tcl on IOS with some minor mods.  Take a look at

http://www.tcl.tk/about/netserver.html .  What you need to do, is to wrap these scripts in the syntax of the EEM.  For example, on the side Server:

::cisco::eem::event_register_none

namespace import ::cisco::eem::*
namespace import ::cisco::lib::*

array set arr_einfo [event_reqinfo]

# Echo_Server --
#     Open the server listening socket
#     and enter the Tcl event loop
#
# Arguments:
#     port     The server's port number

proc Echo_Server {port} {
    set s [socket -server EchoAccept $port]
    vwait forever
}

# Echo_Accept --
#     Accept a connection from a new client.
#     This is called after a new socket connection
#     has been created by Tcl.
#
# Arguments:
#     sock     The new socket connection to the client
#     addr     The client's IP address
#     port     The client's port number
     
proc EchoAccept {sock addr port} {
    global echo

# Record the client's information

puts "Accept $sock from $addr port $port"
    set echo(addr,$sock) [list $addr $port]

# Ensure that each "puts" by the server
    # results in a network transmission

fconfigure $sock -buffering line

# Set up a callback for when the client sends data

fileevent $sock readable [list Echo $sock]
}

# Echo --
#     This procedure is called when the server
#     can read data from the client
#
# Arguments:
#     sock     The socket connection to the client

proc Echo {sock} {
    global echo

# Check end of file or abnormal connection drop,
    # then echo data back to the client.

if {[eof $sock] || [catch {gets $sock line}]} {
     close $sock
     puts "Close $echo(addr,$sock)"
     unset echo(addr,$sock)
    } else {
     puts $sock $line
    }
}

Echo_Server $arr_einfo(arg1)

Save as EEM Tcl font (assuming that this script lives in flash: / policies such as no_echo_server.tcl on the device):

Event Manager user Directorystrategie flash: / policies

political event manager no_echo_server.tcl

Then run it from the EXEC mode:

Manager of event executed no_echo_server.tcl 3333

That starts a socket listening on tcp/3333 on this unit.

On the client machine, create a script named no_echo_client.tcl with:

::cisco::eem::event_register_none

namespace import ::cisco::eem::*
namespace import ::cisco::lib::*

array set arr_einfo [event_reqinfo]

#
# A client of the echo service.
#

proc Echo_Client {host port} {
    set s [socket $host $port]
    fconfigure $s -buffering line
    return $s
}

set sock [Echo_Client $arr_einfo(arg1) $arr_einfo(arg2)]
puts $sock "Hello!"
gets $sock response
puts "Response is $response"

Yet once, register for this policy, then run it from EXEC mode with:

Manager of event executed no_echo_client.tcl 10.1.1.1 3333

10.1.1.1 pointing to the IP address of the first (that is, the server) device.

That's all.  This is a simple client/server example on IOS with EEM.

Tags: Cisco Network

Similar Questions

  • Installation of ActiveState Tcl/Tk and Python 3.5.2

    I installed the package 3.5.2 Python from python.org and by their recommendation went to activestate.com and downloaded and installed recommended Tcl/Tk package. When IDLE was opened it gave a message that Tcl/Tk is unstable and it appeared that the version was provided with the operating system, not that of ActiveState.com. I have more information about what I did to Pixelistes.com here: questions about installing Python.

    The problem would be that I installed Python 3.5.2 until I installed the ActiveState Tcl/Tk? I found some information on when the dynamic linker chooses the Tcl/Tk framework (at the time of importation) to post a link but did not understand the consequences. I wonder if Python 3.5.2 installation before I installed the framework recommended Tcl/Tk due to the dynamic linker to link the Tcl/Tk by Apple instead. I might need to tell the linker to use the new framework. Any ideas appreciated.

    When you run idle, by default, this is/usr/bin/idle that is installed with OS X (El Capitan) as the Python 2.7.10 distribution. It was compiled to find the v8.5.9 of ActiveState Tcl that Apple continues to ship.

    When you installed Python 3.5.2 and I hope that you have not installed it on OS X Python existing, it was a precompiled binary distribution that cannot have been compiled about what anyone more than available executives of Tcl/Tk that were part of Mac OS X at the time. Even if you have run idle3 in this Python 3.5.2 distribution don't you may see no change in support of Tcl/Tk.

    When we install Python for a like Homebrew package manager, or alternatively, generates the source code, there are parameters of generation (for example - with-tcl-tk) that tell the source Python 3.5.2 code looking for executives of Tcl/Tk and use + 8.6.4 ActiveState libraries if they are. As idle3 is compiled at the time too, he knows that he has to use the most recent available Tcl/Tk framework. This is the case with my idle3.

    If you plan to build your own Python 3.5.2 you will need the latest tools of command line for (OS X El Capitan), and I encourage you to put the distribution in the tree/usr/local. I've patched and always use pythonbrew for several juggling Python distribution, as I installed v2.7.12 and 3.5.2. Two of these Python distributions I would build on ActiveState Tcl/Tk libraries.

  • Removed Dylibs of Tcl/Tk in El Capitan update

    Hello

    I upgraded a computer to El Capitan and discovered that a bunch of the dylibs used by Tcl/Tk have been removed from their repertoires by the update.  Img package, for example, consists of a bunch of libraries in System/Library/Tcl/8.5/Img1.4.  They have just removed by the update.

    Before the update (10.10.5), this directory contained 23 dylibs.  After the update (10.11.5), no dylibs.  You can verify this by checking the directory, or by typing tclsh from the Terminal prompt and try the command package requires Img.  Work before the update, found after the update package.

    I tried to chat with a technical support on this issue, but I think the tech support person thought I was talking some downloaded 3 application of part (Tcl/Tk is delivered with all the Mac Out of the box, just like Perl, Python, awk, grep, etc..)  They could only hazard a guess why some files may be missing, in general, a Mac to date.

    My question is twofold: first, can anyone confirm that it's not just my machine?  Secondly, how can I present this as a bug report?  I tried to find where to submit it, but I only find options as-live chat with a guy or talking to someone on the phone.  I don't want to chat about it, let me submit it as a bug.

    can anyone confirm that it's not just my machine?

    It is not only your machine. I don't know if there is never shared in this folder libraries, but there is none now. If they were part of a third-party facility, they would indeed have been removed, because third party software are not allowed in the file system (with a few exceptions.)

    I want to present it as a bug.

    I doubt that Apple would consider it as a bug. They say that if you need components that are not included in the operating system, you must install a distribution of Tcl/Tk to third party compatible with El Capitan. It installs in the folder root of the library.

  • Protocol of socket error .dmg

    Hello

    I m getting an error after installing a .dmg file.

    'bad protocol socket.

    I tried with the steam file, a download of safari and firefox and other files and all the same.

    What can be the problem?

    If one do to a comand + R and reinstall the os x that I lose my files in my mac?

    10.11.5 OSX

    See this link... https://origin-discussions-us.Apple.com/message/30241578#30241578

    Basically, you have to reinstall OSX Recovery Mode.

    Simply choose reinstall and you won't lose anything. You should have a back right up.

  • I have problems to make my battery charged, because the cable does not have a link solid with the socket of the phone.  The problem seems compatible with a lot of cables, so I think the problem is with the phone. Can it be fixed?

    I have problems to make my battery charged, because the cable does not have a link solid with the socket of the phone.  The problem seems compatible with a lot of cables, so I think the problem is with the phone. Can it be fixed?

    Probably there is debris and dust in the decision-making of the lightning.  Serve with compressed gas canned (NEVER orally).  If this doesn't help, try electronic contact cleaner has a q - Tip.  Finally, take it to Apple.

  • Slow, Satellite Pro M70: xferrecv_recvMain2(): error socket() 3135, 10106

    Hello world

    Since yesterday, I have problems with my laptop.
    He needs minutes after minutes to start and then I get no connection to my WLan system. When starting, I get after a while the message "xferrecv_recvMain2(): error socket() 3135, 10106.»

    Right now I can t use the laptop, because she needs a lot of time to react after you start a program etc.

    What is a defect on the chips of RAM?

    I use the factory ones, not additional ones.

    Thank you very much for your support.

    Best regards
    Patrick

    You can test the memory with Memtest www.memtest.org. Its a floppy disk or a bootable CD.

    The HARD drive could be faulty, check using the advanced options of Hitachi DFT test (find it in Google).

  • Tecra 8100 TV problems? What Socket? cable?

    OK so I have a Tecra 8100 laptop

    > running everything well... except that I can not get the TV out socket work...
    > Ive got windows XP on it...

    first thing I want to know about the housing - it is a Jack of 3.5 mm (NOT of RCA or S-vide0)

    > so I finally managed to get a Jack 3.5 mm cable video, audio...
    > which connected to the TV... nothing

    I have the cable entry?

    in display properties, I installed the drivers of duo, and there are a few additional options...

    > what confused me, it's that there are 2 monitors there... but is it because of the VGA?
    > I tried pressing FN + F5... but not had any luck

    Is there something simple that im missing like a cable?
    > or a piece of software...

    Hello

    As much as I know on the right side you will find a video taken of output. To use this video on the service, you will need to use a RCA video connector.
    Please also check the settings in the BIOS. Here, you set the type of TV signal and select television as an output device.

    To connect the TV, please follow these steps:
    1 turn off the computer
    2. use the composite video cable to connect the TV to the video output port
    3 turn on the TV
    4. turn on the laptop

    I hope this helps.

  • 17 '' HP Pavilion: upgrade HP Pavilion - Socket FCBGA1170 - 4 core CPU N3700 @ 1.60 GHz

    I have a 17 "HP Pavilion notebook with an Intel Pentium CPU N3700 @ 1.60 GHz on a Socket BGA1170, with 4 cores and Max TDP of 6W with 8 GB of RAM with Windows 10.

    I find this combination very slow and walked if I could switch the CPU to a faster? I look forward to your recommendations

    Another consideration is the upgrade of the standard SATA 1 TB HD HTS541010A9E680 to a 1 TB SSD. Or would it be too expensive.

    Thanking you in advance for your answers.

    Fred

    +++ fK

    We do not have your exact model, but on most of the Trail Bay models I've seen (series N processors Pentium and Celeron) the processor is soldered to the motherboard and there is no distinct ability to change the processor. FCBGA1170 means that it is a Ball Grid Array which means welded on. 1 TB SSD are about $300-380.

  • How to open sockets?

    I used the front sockets on older Unix, but now calls are slightly different and I wonder:

    Can anyone show me a simple C code for opening a socket (for the portion & client)?

    I would like to start here:

    https://developer.Apple.com/library/Mac/documentation/NetworkingInternet/concept ual/NetworkingTopics/Articles/UsingSocketsandSocketStreams.html

  • HP Envy Phoenix 810-460: HP Envy Phoenix 810-460 K5G86AA MSI Kaili2 MS - 7826 V2 Intel Socket 1150 Broadwell upgrade

    My father bought this computer in August of last year just before that the 1150 of Socket Intel chips Broadwell (5775 i7 and i5 5675 C).  This HP computer contains a Z97 chipset which should have support for both of these chips with a BIOS update.  However, I have not seen any this BIOS update released from HP the HP PC Hardware Diagnostics UEFI which I can't not running on his computer.  It will be prudent to drop the chip in one of these processors without a BIOS update and properly executed?  Thank you.

    Greetings,

    I don't think that the Broadwell chip will work on this PC BIOS from HP support.

    There is a BIOS Update HP under Win 8.1 (sp71809.exe). There is no documentation HP included that this update of the BIOS also supports Broadwell.

    See you soon!

  • Satellite L30: It is possible made evolution of microphone to a line-in socket

    Is their anyway to change the mic to a line plug into the socket
    I presume that the L30 doesn't have a line in socket

    Thanks for the tips

    Unfortunately, I put t think something like that is possible.
    Is that the laptop does not support Line-in input.

    But maybe you'll be able to buy a PCMCIA sound card that supports this interface.

  • Qosmio F20-130 - damaged USB socket

    OK, I don't want just a response 'Please take it to a reputable Toshiba dealer!

    I just tried to put a USB device into my USB port the closest, and he seems to have completely pushed into the workings of the plug! I have not forced or something!

    Are part of the motherboard USB Sockets? If Yes, what is the cost to retail for a new Board of Directors? Can you recommend someone near St Albans? I don't want to be without this laptop for awhile but have free a few weeks at the end of January.

    Concerning

    Keith

    Hello

    I won't you please take it to a reputable Toshiba dealer"but ask someone to Toshiba service provider in your country for advice
    As Reaver mentioned ports are part of the motherboard, but you don t you need to replace the whole motherboard. The technician with experience can fix these ports

    On this page you will find the database with the service provider in the world:
    http://EU.computers.Toshiba-Europe.com/-> support-> support & downloads-> from the home page find an authorized service provider

  • More than 2 Sockets of RAM Qosmio X 770 - 107 or another?

    Hey guys,.

    I found two entries in tools Systeminformation, and I can't believe if its right.

    [4 Slots of Ram | http://imageshack.us/photo/my-images/804/ram4.jpg/]

    If there are really 4 Ram slots, has perhaps its best to run Notepad with 16 GB of RAM... (4 x 4 GB - 8 GB possible Modules not supported).

    Here, someone who can check if it has really 4 Sockets in RAM in the laptop?

    I used to make the visible slots on the programs:

    EVEREST Corporate Edition
    CPU - Z 64

    Hi nvomlehn

    The Qosmio X 770 motherboard supports two memory locations.
    The information that will certainly not my CPU - Z.

    Welcome them

  • Satellite L300 - T2FTP Windows sockets of initialization failed

    After login, I get the following message:

    T2FTP Windows sockets of initialization failed

    At the same time, the system issues a message that he has found a new unknown device and the driver must be installed.

    Before that I did NOT add a new hardware device.

    Click the button start only generates a message: Windows Explorer does not react.
    It is impossible to call any other routine.

    Unfortunately I can not find my recovery CDROM.

    Are there opportunities to save my system?

    Toshiba Satellite L300 model PSLB8E
    Windows VISTA-32 bit

    Hello

    I never met such a problem. Have you installed any programs recently? It seems that the software related issue. To be honest, it is sometimes easier to reinstall the operating system than to try to fix it.

  • Satellite L30: CFSServ "Windows Socket error.

    Hello

    Every time I try to go on internet, this warning sign appears (a yellow triangle with an exclamation mark inside) saying CFSServ "Windows socket error.
    It allows me to go on my internet (what is broadband) gave me solutions such as put the Windows XP CD in the CD drive and repair of each file, but the thing is, I never gave me a cd of Windows XP in the first place! As soon as I opened the box and set up the laptop, there is no CD of windows xp.
    (I'm typing this from my desktop computer) I wish that all solutions on how to get rid of this problem.

    Thanks to all who help.

    Post edited by: ringmaster164

    First you get a Toshiba Recovery CD and not an original Windows OS CD.
    In this case, if you want you can retrieve the whole OS. All Toshiba drivers are preinstalled on the image.

    Now to the error:
    cfsserv.exe is a process belonging to Toshiba ConfigFree utility and search wireless devices.
    However, malware often use the names of valid program to try to hide themselves. So, please run a full scan with Ad-Aware in making sure you have the latest definitions file.

    If it doesn t work I recommend the ConfigFree tool for some audit settings.

Maybe you are looking for

  • in el capitan 'Image Capture' will not open a "Disk Image" file of Adobe

    I'm trying to update to the latest version of Adobe Flash Player.  My iMac (El Capitan, latest version) told me that 'image Capture' cannot open a file in 'picture disc '.  I'm stuck.

  • "organize bookmarks" no longer appears in the bookmarks menu. Where is he?

    "Organize bookmarks" has been a part of menu under Favorites. As of today, its is no longer there. How to find it or get it for routine use? I am using Windows 7, 64-bit. Firefox worm 4

  • Adapter replacement necessary for Equium A300D

    My original power supply Part No.: PA3468E packed in and I need a replacement. I have looked around, but only seem to be able to find 'Kensington' those but am afraid that they are not compatible as previous adptor didn't output 19V, 17V. Did someone

  • Errors by using SIF data connect?

    I'm opening a FIS (somat informtaion file) file using the plugin of FIS data on the Web site of NOR.  It works great for files less than 1 GB.  When I try to open higher than 1 GB files I get the following error. Error: Access Violation Address of th

  • How to enlarge the characters

    When I click on the internet icon explore the site opens up really small.  I can't read the characters at all.  How to enlarge printing while it's like it used to be.