Skip to content

Commit 236134c

Browse files
committed
DefaultProtocol
1 parent ecd44b6 commit 236134c

File tree

5 files changed

+95
-7
lines changed

5 files changed

+95
-7
lines changed

Src/EngineIoClientDotNet.Tests.mono/ClientTests/ServerConnectionTest.cs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,47 @@ public void UpgradeCookie()
397397
Assert.Equal("got cookie", test);
398398
}
399399

400+
//[Fact]
401+
//public void PrimusEndpoint()
402+
//{
403+
// var log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod());
404+
// log.Info("Start");
405+
// _manualResetEvent = new ManualResetEvent(false);
406+
407+
// var events = new Queue<string>();
408+
409+
// var options = CreateOptions();
410+
// options.Cookies.Add("foo", "bar");
411+
// options.Hostname = "testme.quobject.com/";
412+
// options.Path = "primus";
413+
// var socket = new Socket(options);
414+
// //var socket = new Socket("testme.quobject.com");
415+
// socket.On(Socket.EVENT_OPEN, () =>
416+
// {
417+
// log.Info("EVENT_OPEN");
418+
// socket.Send("cookie");
419+
// });
420+
// socket.On(Socket.EVENT_MESSAGE, (d) =>
421+
// {
422+
// var data = (string)d;
423+
// log.Info("EVENT_MESSAGE data = " + data);
424+
// events.Enqueue(data);
425+
// if (events.Count > 1)
426+
// {
427+
// _manualResetEvent.Set();
428+
// }
429+
// });
430+
// socket.Open();
431+
// _manualResetEvent.WaitOne();
432+
// socket.Close();
433+
434+
// string result;
435+
// result = events.Dequeue();
436+
// Assert.Equal("hi", result);
437+
// result = events.Dequeue();
438+
// Assert.Equal("got cookie", result);
439+
//}
440+
400441
}
401442

402443
}

Src/EngineIoClientDotNet.Tests.mono/ClientTests/SocketTest.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,5 +80,16 @@ public void SocketOptionCookies()
8080
options.Cookies.Add("name2","value2");
8181
Assert.Equal("foo=bar; name2=value2", options.GetCookiesAsString());
8282
}
83+
84+
[Fact]
85+
public void DefaultProtocol()
86+
{
87+
88+
var log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod());
89+
log.Info("Start");
90+
91+
var socket = new Socket("testme.quobject.com");
92+
Assert.NotNull(socket);
93+
}
8394
}
8495
}

Src/EngineIoClientDotNet.mono/Client/Socket.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,21 @@ public Socket(string uri)
102102
}
103103

104104
public Socket(string uri, Options options)
105-
: this(uri == null ? null : new Uri(uri), options)
105+
: this(uri == null ? null : String2Uri(uri), options)
106106
{
107+
108+
}
109+
110+
private static Uri String2Uri(string uri)
111+
{
112+
if (uri.StartsWith("http") || uri.StartsWith("ws"))
113+
{
114+
return new Uri(uri);
115+
}
116+
else
117+
{
118+
return new Uri("http://" + uri);
119+
}
107120
}
108121

109122
public Socket(Uri uri, Options options)

Src/EngineIoClientDotNet.mono/Client/Socket_net35.cs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,21 @@ public Socket(string uri)
106106
}
107107

108108
public Socket(string uri, Options options)
109-
: this(uri == null ? null : new Uri(uri), options)
109+
: this(uri == null ? null : String2Uri(uri), options)
110110
{
111+
112+
}
113+
114+
private static Uri String2Uri(string uri)
115+
{
116+
if (uri.StartsWith("http") || uri.StartsWith("ws"))
117+
{
118+
return new Uri(uri);
119+
}
120+
else
121+
{
122+
return new Uri("http://" + uri);
123+
}
111124
}
112125

113126
public Socket(Uri uri, Options options)
@@ -346,7 +359,7 @@ public class Options : Transport.Options
346359
public string QueryString;
347360

348361

349-
362+
350363
public static Options FromURI(Uri uri, Options opts)
351364
{
352365
if (opts == null)
@@ -365,8 +378,8 @@ public static Options FromURI(Uri uri, Options opts)
365378

366379
return opts;
367380
}
368-
369-
381+
382+
370383
}
371384

372385

TestServer/server.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ var
1212
},
1313
server,
1414
https,
15-
http;
15+
http,
16+
primus_server;
1617

1718

1819
console.log("https port = " + config.server.ssl_port);
@@ -24,18 +25,27 @@ var
2425

2526
console.log("http port = " + config.server.port);
2627
http = require('http').createServer(app);
27-
server = require('engine.io').attach(http, {'pingInterval': 500});
28+
server = require('engine.io').attach(http, { 'pingInterval': 500 });
29+
primus_server = require('engine.io').attach(http, { 'pingInterval': 500, 'path' : '/primus/engine.io' });
2830
http.listen( config.server.port, function() {
2931
console.log('Engine.IO server listening on port', config.server.port);
3032
});
3133

3234

35+
primus_server.on('connection', function (socket) {
36+
console.log('primus_server connection');
37+
socket.send('hi');
38+
});
39+
40+
3341
http.on('request', function(request, response) {
3442
//console.log('request ' +util.inspect( request.headers));
3543

3644
});
3745

3846

47+
48+
3949
server.on('connection', function(socket){
4050
socket.send('hi');
4151

0 commit comments

Comments
 (0)