Sponsored Content
Top Forums UNIX for Advanced & Expert Users "Phantom character" in Socket (RESOLVED) Post 302332247 by trutoman on Thursday 9th of July 2009 09:18:12 AM
Old 07-09-2009
"Phantom character" in Socket (RESOLVED)

Hi everyone:

I have built a tcl script, this script communicate with an ADA program trough a socket, sending binary data, the sender proc is this one:

The code where im sending info is here:
Code:
proc p_send_data { DATA } {
  global connection
  puts "Sending trough $connection..."
 
  # This is just the string of bytes im sending
  binary scan $DATA H22 hexa
  puts "IM SENDING THIS ------>  $hexa"

  # Put it trough socket
  puts -nonewline "$connection" $DATA
  flush $connection
  }

It usually works fine, but with some values of DATA, socket, a little demon or something is adding a byte to my string !!

The output of program "IM SENDING THIS -----> 0109450900018813bc0400"

Like you can see this line is printed just before puts data in socket.

The "tcpdump" capture ----------------------------------> 010945090001c28813bc0400

The bytes are the same excepts that c2 insertion.

With strace i can see how system writes in socket this:

Code:
write(1, "IM SENDING THIS ------>  010945090001"..., 44IM SENDING THIS ------>  0109450900018813bc0400) = 44
sendto(4, "\1\tE\t\0\1\302\210\23\302\274\4\0001212", 17, 0, NULL, 0) = 17

Sometimes with different values of DATA this byte "c2" appears......always in the same position !! . After looking info trough internet, iknow that c2 is 194 in decimal and it doesn't look like a dangerous character like "\00" "\7f" could be.

Perhaps an error in c libraries of sockets??

This is my system : Linux 2.6.9-67
TCLInterpreter : 8.4

Plz Help me . THX!!

---------- Post updated 09-07-09 at 03:18 PM ---------- Previous update was 08-07-09 at 07:01 PM ----------

Nobody response.

I have fixed it !!!! exactly 20 hours after.

Par default a socket connection its created with "-encoding = utf-8" . But i was sending binary data, so sometimes (when my binary bytes matched up with a ascii code) it interpret that like some ascii char and the socket translated automatically to ascii code.
So the solution is to configure socket with "-encoding = binary".in tcl.
"fconfigure connection -encoding binary"

it was quite easy ....... like ever.
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

removing the "\" and "\n" character using sed or tr

Hi All, I'm trying to write a ksh script to parse a file. When the "\" character is encountered, it should be removed and the next line should be concatenated with the current line. For example... this is a test line #1\ should be concatenated with line #2\ and line number 3 when this... (3 Replies)
Discussion started by: newbie_coder
3 Replies

2. UNIX for Dummies Questions & Answers

Command Character size limit in the "sh" and "bourne" shell

Hi!!.. I would like to know what is maximum character size for a command in the "sh" or "bourne" shell? Thanks in advance.. Roshan. (1 Reply)
Discussion started by: Roshan1286
1 Replies

3. UNIX for Advanced & Expert Users

Command Character size limit in the "sh" and "bourne" shell

Hi!!.. I would like to know what is maximum character size for a command in the "sh" or "bourne" shell? Thanks in advance.. Roshan. (1 Reply)
Discussion started by: Roshan1286
1 Replies

4. Shell Programming and Scripting

Command Character size limit in the "sh" and "bourne" shell

Hi!!.. I would like to know what is maximum character size for a command in the "sh" or "bourne" shell? Thanks in advance.. Roshan. (1 Reply)
Discussion started by: Roshan1286
1 Replies

5. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

6. Shell Programming and Scripting

Using sed to find text between a "string " and character ","

Hello everyone Sorry I have to add another sed question. I am searching a log file and need only the first 2 occurances of text which comes after (note the space) "string " and before a ",". I have tried sed -n 's/.*string \(*\),.*/\1/p' filewith some, but limited success. This gives out all... (10 Replies)
Discussion started by: haggismn
10 Replies

7. UNIX for Advanced & Expert Users

"Phantom" overwrite with dd on sda*?

Greetings. Just wondering about a little "quirk" which I seem to have found when using dd ;) (FWIW on that note, I'm using a flash install of Parted Magic to run dd in these tests...) Thinking about it, there should be some measurable excitement associated withdd if=/dev/zero of=/dev/sda*... (4 Replies)
Discussion started by: LinQ
4 Replies

8. Post Here to Contact Site Administrators and Moderators

Marking thread "Resolved"

Can the OP of a thread still mark the thread "Resolved" when the question is answered? (2 Replies)
Discussion started by: wbport
2 Replies

9. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies
catch(n)						       Tcl Built-In Commands							  catch(n)

__________________________________________________________________________________________________________________________________________________

NAME
catch - Evaluate script and trap exceptional returns SYNOPSIS
catch script ?varName? _________________________________________________________________ DESCRIPTION
The catch command may be used to prevent errors from aborting command interpretation. Catch calls the Tcl interpreter recursively to exe- cute script, and always returns without raising an error, regardless of any errors that might occur while executing script. If script raises an error, catch will return a non-zero integer value corresponding to one of the exceptional return codes (see tcl.h for the definitions of code values). If the varName argument is given, then the variable it names is set to the error message from interpret- ing script. If script does not raise an error, catch will return 0 (TCL_OK) and set the variable to the value returned from script. Note that catch catches all exceptions, including those generated by break and continue as well as errors. The only errors that are not caught are syntax errors found when the script is compiled. This is because the catch command only catches errors during runtime. When the catch statement is compiled, the script is compiled as well and any syntax errors will generate a Tcl error. EXAMPLES
The catch command may be used in an if to branch based on the success of a script. if { [catch {open $someFile w} fid] } { puts stderr "Could not open $someFile for writing $fid" exit 1 } The catch command will not catch compiled syntax errors. The first time proc foo is called, the body will be compiled and a Tcl error will be generated. proc foo {} { catch {expr {1 +- }} } KEYWORDS
catch, error Tcl 8.0 catch(n)
All times are GMT -4. The time now is 11:28 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy