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
source(n)						       Tcl Built-In Commands							 source(n)

__________________________________________________________________________________________________________________________________________________

NAME
source - Evaluate a file or resource as a Tcl script SYNOPSIS
source fileName source -encoding encodingName fileName | _________________________________________________________________ DESCRIPTION
This command takes the contents of the specified file or resource and passes it to the Tcl interpreter as a text script. The return value from source is the return value of the last command executed in the script. If an error occurs in evaluating the contents of the script then the source command will return that error. If a return command is invoked from within the script then the remainder of the file will be skipped and the source command will return normally with the result from the return command. The end-of-file character for files is "32" (^Z) for all platforms. The source command will read files up to this character. This restriction does not exist for the read or gets commands, allowing for files containing code and data segments (scripted documents). If you require a "^Z" in code for string comparison, you can use "32" or "u001a", which will be safely substituted by the Tcl interpreter into "^Z". The -encoding option is used to specify the encoding of the data stored in fileName. When the -encoding option is omitted, the system | encoding is assumed. EXAMPLE
Run the script in the file foo.tcl and then the script in the file bar.tcl: source foo.tcl source bar.tcl Alternatively: foreach scriptFile {foo.tcl bar.tcl} { source $scriptFile } SEE ALSO
file(n), cd(n), encoding(n), info(n) KEYWORDS
file, script Tcl source(n)
All times are GMT -4. The time now is 01:24 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy