Websocket and TCP - tcp

According to my knowledge, Websocket is a message-based protocol and using TCP as the transport layer. But TCP itself is a stream-based protocol. Can someone explain
how websocket message in segmented in TCP?
what is framing in Websocket?
what's advantage of using message in Websocket? I saw from here asking that Why are WebSockets frame-based and not stream-based?
Correct me if I have any misconception.

To send a specific data format like a webSocket frame over TCP, you just have to define the data format so that the reader of the stream knows where the frame starts and ends based on the format. One typical way is to send a set of data that includes a fixed size (known in advance) header format that includes a length of the total frame and then you send the rest of the frame that is that length. The reader can then read the initial fixed size data, read the length out of that and then know how much more to read to get the whole frame.
what is framing in Websocket?
You can read about the whole webSocket frame here and here's a look at how a webSocket frame is structured.
Frame format:
​​
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-------+-+-------------+-------------------------------+
|F|R|R|R| opcode|M| Payload len | Extended payload length |
|I|S|S|S| (4) |A| (7) | (16/64) |
|N|V|V|V| |S| | (if payload len==126/127) |
| |1|2|3| |K| | |
+-+-+-+-+-------+-+-------------+ - - - - - - - - - - - - - - - +
| Extended payload length continued, if payload len == 127 |
+ - - - - - - - - - - - - - - - +-------------------------------+
| |Masking-key, if MASK set to 1 |
+-------------------------------+-------------------------------+
| Masking-key (continued) | Payload Data |
+-------------------------------- - - - - - - - - - - - - - - - +
: Payload Data continued ... :
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
| Payload Data continued ... |
+---------------------------------------------------------------+
what's advantage of using message in Websocket?
It's unclear what you're asking with this. Reasons for using a webSocket connection include the following:
The ability to "push" data from server to the client at any time.
Very low overhead way to send data from either client to server or server to client at any time (much lower overhead for repeated packets than an http request).
Ability to have a persistent connection over which you can do many things without having to conform everything to the http request/response format.

Related

Interpreting and converting zone file data

I have a zone for a single TLD. I am trying to process the file data and convert it into JSON for other services that uses this data. Here's the first five lines of the file I have:
com. 900 in soa a.gtld-servers.net. nstld.verisign-grs.com. 1612915221 1800 900 604800 86400
0-------------------------------------------------------------0.com. 172800 in ns ns1.domainit.com.
0-------------------------------------------------------------0.com. 172800 in ns ns2.domainit.com.
0-------------------------------------------------------------5.com. 172800 in ns fns.frogsmart.net.
0-------------------------------------------------------------5.com. 172800 in ns sns.frogsmart.net.
0-------------------------------------------------------------5.com. 172800 in ns tns.frogsmart.net.
Now I am not sure as how to interpret this file's data. I have looked at reference and example zone files at multiple places but, it does not resemble this format. One of the references can be found here. I just need some pointers on how to interpret each line. My understanding are the following:
The first value is the domain name
The next value is a number which, if I use the first line as header seems to be 900 (not sure what is)
The next value is in (not sure what this is)
The next value is soa which is ns (I think this means Start of Authority for domain is with Name server)
Lastly, the name server which, if I use the first line as header seems to a.gtld-servers.net (I think this is the primary SOA address)
Now the other properties (the first line I think indicates 10 properties) but these are not present in this file I am trying to process. That's all I could figure out so far and some help will be greatly appreciated.
First a warning: zonefiles can be big, especially .com one and converting that to JSON, especially if you intend to fully build the object in memory before using it, you might have trouble.
So you should start by asking yourselves if you really need all the data (for example as seen below what will you do with SOA content?) and if JSON is the most adequate representation, especially if not in a streaming way.
DNS data is explained in RFC 1034+1035.
More specifically §3.3.13 in RFC1035:
3.3.13. SOA RDATA format
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
/ MNAME /
/ /
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
/ RNAME /
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
| SERIAL |
| |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
| REFRESH |
| |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
| RETRY |
| |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
| EXPIRE |
| |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
| MINIMUM |
| |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
where:
MNAME The of the name server that was the
original or primary source of data for this zone.
RNAME A which specifies the mailbox of the
person responsible for this zone.
SERIAL The unsigned 32 bit version number of the original
copy
of the zone. Zone transfers preserve this value. This
value wraps and should be compared using sequence space
arithmetic.
REFRESH A 32 bit time interval before the zone should be
refreshed.
RETRY A 32 bit time interval that should elapse before a
failed refresh should be retried.
EXPIRE A 32 bit time value that specifies the upper limit on
the time interval that can elapse before the zone is no
longer authoritative.
But do not that the semantics have changed in later RFCs, the MINIMUM is now called the NEGATIVE TTL.
Also IN (case not significant) means INternet but all records will have that, consider it as a left over of past DNS experiments around classes that never worked.

Why is 0x7E commonly used as Start Delimiter in Communication Protocol?

i am looking to implement a serial communication between 2 devices using just a simple communication.
It seem that protocol such as those used in HDLC and xBee uses 0x7E as the start delimiter.
Is there any particular reason or i can use any character as an alternative.
The reason is related to framing of data.
They needed a flag that will mark a beginning and an end of transmission.
They wanted to be able to replicate that flag few times if needed - in example if you send
01111110 01111110 01111110 - it is very easy to identify this set compared to other sets even if some bits didn't made it to the other side, so it is uniquely much less error prone.
(0x7E=01111110)
Extended Example:
machine 1 sent: 01111110 01111110 01111110
some options for error in receive:
machine 2 recv: 011110011111001111110 - notice that you can identify 3 frames very easy.
machine 2 recv: 11111001111110011111 - again you can identify 3 frames quite easy.
machine 2 recv: 01111110111111001111110 - once more 3 frames can be identified quite easy.
Now let's see what happens if we choose different sequences as flags.
Example 1:
machine 1 sent: 01011010 01011010 01011010 (here flag chosen is 01011010)
some options for error in receive:
machine 2 recv: 010010100101101001011010 - you cannot identify if those are even frames..
Example2:
machine 1 sent: 00011000 00011000 00011000 (here flag chosen is 00011000)
some options for error in receive:
machine 2 recv: 00110000001100000011000 - this one is ok... we can easy see 3 frames.. but..
machine 2 recv: 0010000001100000011000 - this is harder.. could be 3 frames but can't be sure..
You can read more in Wikipedia information about HDLC (check the frames subject)
One more thing.. SO Folks I know this has a flame potential :)
Please keep in mind I didn't choose this arbiter sequence.. I only explain the reason for this particular sequence as choice.

How to sort logs files by date iso8601?

My logs are not ordered by date :
1. 2013-09-13T09:44:10.581-0400 - 4mainthreadtest#test.com - (v1.6.88) - REPLAY >> Scheduling replay in 2 seconds
2. 2013-09-13T09:44:10.546-0400 - 4mainthreadtest#test.com - (v1.6.88) - REPLAY >> Delay of 106803.116188 seconds
3. 2013-09-13T09:44:10.581-0400 - 4mainthreadtest#test.com - (v1.6.88) - REPLAY >> Hexoskin - replay completed 2013-09-13T09:44:10.535-0400 - 4mainthreadtest#test.com - (v1.6.88) - Hexoskin SDK - Playback ended with 0x0000
How can I order them ?
I looked at the command line sort but I was not able to sort by date iso8601.
You want to sort by the second field (2013-09-13...), not the whole line. You can specify that using the -k parameter:
sort -k 2 log.txt

TCP/IP communication from the unix server to the Pure Data

I am interested in TCP/IP communication from the Unix server to the Pure Data. I have it realized using sockets on the Unix server side, and netclient on the Pure Data side. I exploited the chat-server tutorial for this (3.Networking > 10.chat_client.pd).
Now the problem lies that the server is streaming the data out as a "string" message delimited with ";"
My question is, is there a way to send something other than string message to Pure Data, like byte-stream or serialized number stream? Can Pure Data receive such messages?
Since string takes too many bytes to transfer, for example number "1024;" is already 5 bytes, while such an integer number is just 4 bytes.
UPDATE: For everyone that stumbles upon this post in search for the answer.
Apparently [netclient] on the Pure Data side cannot receive nothing else than ; delimited messages.
So the solution for the problem posed above:
My question is, is there a way to send something other than string message to Pure Data, like byte-stream or serialized number stream? Can Pure Data receive such messages?
The solution is to use [tcpclient], it can receive byte-stream data.
Now my question is, how do I get four compact numbers to work with?
Now I have a series of bytes, at least in the correct order.
From my UNIX server I am sending a structure
typedef struct {
int var_code;
int sample_time;
int hr;
float hs;
} phy_data;
Sample data might be 2 1000000 51 2000.56
When received and printed in Pure Data I get output like this:
: 0 0 0 2 0 10 114 26 0 0 0 51 0 16 242 78
You can notice number 2 and number 51 clearly, I guess the others are correct as well.
How can I get these numbers back to a usable format?
Maybe some manipulation with [bytes2any] and [route], but I haven't been able to extract the data with it?
here's an outline of what you have to do:
repackage the bytelist to small messages of the correct size for the various types.
since all your elements are 4 byte long, you simply repackage your list (or bytestream, as TCP/IP doesn't guarantee to deliver your 16 bytes as a single list, but could also decide to break it into a list of arbitrary length) to a number of 4 atom lists.
the most stable way, would probably be to 1st serialize the list (check the "serializer" example in the [list] help) and than reassamble that list to 4 elements.
if you can use externals like zexy you could use [repack 4] for that.
if you trust [netclient] to output your messages as complete lists, you could simply use a large [unpack ....] and 4 [pack]s
interpret the raw data for each sublist
integers is rather simple, floats are way more complicated
integers:
|
[unpack 0 0 0 0]
| | | |
[<< 8] | | |
| | | |
[+ ] | |
| | |
[<< 8] | |
| | |
[+ ] |
| |
[<< 8] |
| |
[+ ]
|
floats are left as an exercise to the user :-)
the real solution to your problem would be to use a well-defined application-layer protocol, rather than brew your own.
the most widespread protocol in use for applications like Pd, is certainly OSC.
in order to decode the raw OSC-bytes into Pd-messages, use [unpackOSC] (part of the "mrpeach" library; on Debian, you install it via the pd-osc package)
on the "server" side, you can use liblo for encoding data and sending it.
note
be aware that since OSC is packet-based, you will need a packetizing mechanism for stream-based protocols like TCP/IP. as with OSC-1.2, this should be SLIP. liblo should already take care of this. check the patches accompanying [unpackOSC] for how to do this within Pd.
all this is not needed if you are using a UDP as a transport.

I can not run sahi [duplicate]

This question already has an answer here:
Closed 10 years ago.
Possible Duplicate:
sahi and symfony2
I would like to test behat, mink and sahi with symfony2.
In my file config_test.yml I have
mink:
base_url: http://localhost/Symfony_Standard_2.0.15_2/symfony/web/app_test.php
default_session: symfony
sahi: ~
in my test.feature when I use
Scenario: Open page with products list and check it
Given I am on "/hello"
Then the response should contain "hello"
the result is well:
1 scenario (1 passed)
2 steps (2 passed)
0m5.112s
But when i add #mink:sahi I get
#mink:sahi
Scenario: Open page with products list and check it #
src\Acme\DemoBundle\Features\test.feature:6
Given I am on "/hello" # Acme\DemoBundle\Features\Context\FeatureContext::visit()
Operation timed out after 5000 milliseconds with 0 bytes received
Then the response should contain "hello" #
Acme\DemoBundle\Features\Context\FeatureContext::assertResponseContains()
1 scenario (1 failed)
2 steps (1 skipped, 1 failed)
0m5.112s
Do you have any idea?
i have solved the problem, in fact, we must run the driver sahi, before starting the test,

Resources