@Amol are you getting any messages at all (you should get a 1-byte / second heart beat). If you are not, it's likely that your connection itself was not established properly.
@Kailash I am able to connect and receive data but data received is not getting parsed properly.
Data Received is byte array of 48 length and i am sending request for full mode Message format for subscription : 1.message = {"a": "subscribe", "v": [12402434]}; 2.message = {"a": "mode", "v": ["full", [12402434]};
@Amol , I looked up the documentation for BitConverter.ToInt16 and 32, and the second parameter is described as 'startIndex'. Your code snippet seems to be passing the endIndex. That means, your code should be in the following manner, right?
int i = BitConverter.ToInt16(e.TextB, 0); int i = BitConverter.ToInt16(e.TextB, 2); int i = BitConverter.ToInt32(e.TextB, 4);
use--> check for BitConverter.IsLittleEndian first
then--> char[] b = new char[4]; Array.Copy(a, 0, b, 0, 4); a = source array 0 = start index in source array b = destination array 0 = start index in destination array 4 = elements to copy
then --> byte[] reversed = bytes.Reverse().ToArray(); on the sub array
Now i can successfully get quote by passing this JSON : {"a": "subscribe", "v": [408065, 884737]}
But i can subscribe neither "ltp" nor "full" by default i am getting "qoute", have tried below formats to change mode but nothing seems getting changed , please let me know what i am missing ?
Yes, thats going to be extremely useful. We lack C# library unlike Python and Java. Hence if someone can post a code starting from authentication, getting token, using the same to make a subscription and then receiving and parsing a full mode quote, thats really going to be helpful
and i have only subscribe for NFO so can i receive data of NSE Reliance.
1: string message = @{'a': 'subscribe', v: [738561]};
ws.Send(JsonConvert.SerializeObject(message));
2: string message = "{\"a\": \"subscribe\", v: [738561]}";
ws.Send(JsonConvert.SerializeObject(message));
3 string message = "{\"a\": \"mode\", \"v\": [\"full\", [738561]}";
ws.Send(JsonConvert.SerializeObject(message));
'{"a": "subscribe", "v": [738561]}'
'{"a": "subscribe", "v": [260355]}'
Data Received is byte array of 48 length and i am sending request for full mode
Message format for subscription :
1.message = {"a": "subscribe", "v": [12402434]};
2.message = {"a": "mode", "v": ["full", [12402434]};
byte[48] :
[0]: 0 [1]: 1 [2]: 0 [3]: 44 [4]: 7 [5]: 162 [6]: 186
[7]: 4 [8]: 0 [9]: 2 [10]: 86 [11]: 182 [12]: 0 [13]: 0
[14]: 0 [15]: 20 [16]: 0 [17]: 0 [18]: 0 [19]: 27 [20]: 0 [21]: 0
[22]: 6 [23]: 206 [24]: 0 [25]: 0 [26]: 32 [27]: 44 [28]: 0 [29]: 0
[30]: 27 [31]: 6 [32]: 0 [33]: 2 [34]: 82 [35]: 106 [36]: 0 [37]: 2
[38]: 88 [39]: 100 [40]: 0 [41]: 2 [42]: 81 [43]: 192 [44]: 0 [45]: 2
[46]: 82 [47]: 106
1.First two byte give o/p as 1 proper
int i = BitConverter.ToInt16(e.TextB, 1);
2.next 2 byte give o/p as 44 proper
int i = BitConverter.ToInt16(e.TextB, 3);
3.next 4 byte give o/p as 147389 but expected o/p was 12402434
int i = BitConverter.ToInt32(e.TextB, 5);
1: System.BitConverter.ToInt16(e.TextB, 1) o/p : 1
2: System.BitConverter.ToInt16(e.TextB, 0) o/p : 256
3.System.BitConverter.ToInt16(e.TextB, 3) o/p : 1836
4.System.BitConverter.ToInt16(e.TextB, 2) o/p : 11264
5.System.BitConverter.ToInt32(e.TextB, 4) o/p : 37731584
6.System.BitConverter.ToInt32(e.TextB, 5) o/p : 147389
Have you succeeded converting above byte() array ? if yes please share with me too as i am facing the issue ,
Hi Kailash , have you tried this at your end ?, i am also getting the same out put as Amol mentioned while converting to int16
You have to reverse the array which you receive but field wise.i.e
byte[48] :
[0]: 0 [1]: 1 [2]: 0 [3]: 44 [4]: 7 [5]: 162 [6]: 186
[7]: 4 [8]: 0 [9]: 2 [10]: 86 [11]: 182 [12]: 0 [13]: 0
[14]: 0 [15]: 20 [16]: 0 [17]: 0 [18]: 0 [19]: 27 [20]: 0 [21]: 0
[22]: 6 [23]: 206 [24]: 0 [25]: 0 [26]: 32 [27]: 44 [28]: 0 [29]: 0
[30]: 27 [31]: 6 [32]: 0 [33]: 2 [34]: 82 [35]: 106 [36]: 0 [37]: 2
[38]: 88 [39]: 100 [40]: 0 [41]: 2 [42]: 81 [43]: 192 [44]: 0 [45]: 2
[46]: 82 [47]: 106
if you want int 32 then take 4 byte from array then reverse the small array and try to convert it.
Actual array : [4]: 7 [5]: 162 [6]: 186 [7]: 4
Reverse Array :[7]: 4 [6]: 186 [5]: 162 [4]: 7
then use System.BitConverter.ToInt32({4,186,162,7})
revert in case of any query
check for BitConverter.IsLittleEndian first
then-->
char[] b = new char[4];
Array.Copy(a, 0, b, 0, 4);
a = source array
0 = start index in source array
b = destination array
0 = start index in destination array
4 = elements to copy
then --> byte[] reversed = bytes.Reverse().ToArray(); on the sub array
then use bit Converter
Now i can successfully get quote by passing this JSON :
{"a": "subscribe", "v": [408065, 884737]}
But i can subscribe neither "ltp" nor "full" by default i am getting "qoute", have tried below formats to change mode but nothing seems getting changed , please let me know what i am missing ?
{"a": "mode", "v": ["full", [408065]}
{"a": "mode", "v": ["ltp", [408065]}
Could you please share the sample piece of code to connect web socket server using C#
Thanks