1

Hi I am new to socket connection and I have test this application and its working . Normally we use host and port to do socket connection . Now I have host and port with server credential . A webrtc is working on web and websocket connection is using following format if Please tell me how to pass user credential while making connection then please let me know . Following url is used in websocket in JS

url = host+port
function connect(url, me, password)
{

  var protocol = window.location.protocol == "http:" ? "ws" : "wss";
  ws = new WebSocket(protocol + "://" + url +"/ws/server?username="+ me +"&password=" + password + "&resource=" + me, "xmpp");
  ws.onopen = onOpen;
  ws.onmessage = onMessage;
  ws.onclose = onConnectionClose;  
}
Razib
  • 10,965
  • 11
  • 53
  • 80
  • Hmm...why going with Websocket when you can use httprequest or Volley...?Personally,I preffer the httprequest because I haven't bothered trying to understand Volley, but as far as I know,Volley rocks. – Vlad May 24 '15 at 08:30
  • Websocket is used on web. I am using socket connection in android and ... may question is that how can we make socket connection via credential ... and thanks for reply .. – saurabh sharma May 24 '15 at 09:46
  • See http://stackoverflow.com/a/29854983/1174054 The standard WebSocket JavaScript API does not provide means to customize HTTP headers. That is, you cannot add `Authorization` header. However, in a native Java application, you can add credentials in a WebSocket request. – Takahiko Kawasaki May 24 '15 at 20:40

0 Answers0