rajsharma123
@rajsharma123
Best posts made by rajsharma123
-
HOW TO CONVERT BINARY DATA OF RECEIVED FROM WEBSOCKET
THIS IS MY CODE
async void ConnectWebsocket1(string agr, string Feedtoken)
{
TokenList tokenList1 = new TokenList();
List<string> tokens1 = new List<string>();
tokens1.Add("3045");
tokenList1.tokens = tokens1;
tokenList1.exchangeType = 1;
TokenList tokenList2 = new TokenList();
List<string> tokens2 = new List<string>();
tokens2.Add("99926009");
tokenList2.tokens = tokens2;
tokenList2.exchangeType = 5;
List<TokenList> tokenLists = new List<TokenList>();
tokenLists.Add(tokenList1);
tokenLists.Add(tokenList2);Params parameters = new Params(); parameters.tokenList = tokenLists; parameters.mode = 1; WebSocketData webSocketData = new WebSocketData(); webSocketData.@params = parameters; webSocketData.action = 1; webSocketData.correlationID = ""; string jsonString = JsonConvert.SerializeObject(webSocketData); var ws = new ClientWebSocket(); ws.Options.SetRequestHeader("Authorization", "Bearer " + agr); ws.Options.SetRequestHeader("x-api-key", "XXXXXX"); ws.Options.SetRequestHeader("x-client-code", "XXXXXX"); ws.Options.SetRequestHeader("x-feed-token", Feedtoken); await ws.ConnectAsync(new Uri("ws://smartapisocket.angelone.in/smart-stream"), CancellationToken.None); byte[] buf = new byte[1056]; ArraySegment<byte> buffer = new ArraySegment<byte>(buf); string mynewstring = jsonString; var encoded = Encoding.UTF8.GetBytes(mynewstring); var sbuffer = new ArraySegment<Byte>(encoded, 0, encoded.Length); await ws.SendAsync(sbuffer, WebSocketMessageType.Text, true, cancellationToken: CancellationToken.None);
while (ws.State == System.Net.WebSockets.WebSocketState.Open)
{
var result = await ws.ReceiveAsync(buffer, CancellationToken.None);if (result.MessageType == WebSocketMessageType.Close) { await ws.CloseAsync(WebSocketCloseStatus.NormalClosure, null, CancellationToken.None); Response.Write(result.CloseStatusDescription + "<br/>"); Console.WriteLine(result.CloseStatusDescription); } else { Response.Write(Encoding.UTF8.GetString(buffer.Array, 0, result.Count) + "<br/>"); break; } }
}
Latest posts made by rajsharma123
-
HOW TO CONVERT BINARY DATA OF RECEIVED FROM WEBSOCKET
THIS IS MY CODE
async void ConnectWebsocket1(string agr, string Feedtoken)
{
TokenList tokenList1 = new TokenList();
List<string> tokens1 = new List<string>();
tokens1.Add("3045");
tokenList1.tokens = tokens1;
tokenList1.exchangeType = 1;
TokenList tokenList2 = new TokenList();
List<string> tokens2 = new List<string>();
tokens2.Add("99926009");
tokenList2.tokens = tokens2;
tokenList2.exchangeType = 5;
List<TokenList> tokenLists = new List<TokenList>();
tokenLists.Add(tokenList1);
tokenLists.Add(tokenList2);Params parameters = new Params(); parameters.tokenList = tokenLists; parameters.mode = 1; WebSocketData webSocketData = new WebSocketData(); webSocketData.@params = parameters; webSocketData.action = 1; webSocketData.correlationID = ""; string jsonString = JsonConvert.SerializeObject(webSocketData); var ws = new ClientWebSocket(); ws.Options.SetRequestHeader("Authorization", "Bearer " + agr); ws.Options.SetRequestHeader("x-api-key", "XXXXXX"); ws.Options.SetRequestHeader("x-client-code", "XXXXXX"); ws.Options.SetRequestHeader("x-feed-token", Feedtoken); await ws.ConnectAsync(new Uri("ws://smartapisocket.angelone.in/smart-stream"), CancellationToken.None); byte[] buf = new byte[1056]; ArraySegment<byte> buffer = new ArraySegment<byte>(buf); string mynewstring = jsonString; var encoded = Encoding.UTF8.GetBytes(mynewstring); var sbuffer = new ArraySegment<Byte>(encoded, 0, encoded.Length); await ws.SendAsync(sbuffer, WebSocketMessageType.Text, true, cancellationToken: CancellationToken.None);
while (ws.State == System.Net.WebSockets.WebSocketState.Open)
{
var result = await ws.ReceiveAsync(buffer, CancellationToken.None);if (result.MessageType == WebSocketMessageType.Close) { await ws.CloseAsync(WebSocketCloseStatus.NormalClosure, null, CancellationToken.None); Response.Write(result.CloseStatusDescription + "<br/>"); Console.WriteLine(result.CloseStatusDescription); } else { Response.Write(Encoding.UTF8.GetString(buffer.Array, 0, result.Count) + "<br/>"); break; } }
}
-
discuss about OutputBaseClass in api
Dear Sir,
My OutputBaseClass object is close on run time why it is close give me reason even internet connection is excellent.
plz reply