我不确定它是否是signalR.i相信signalR正在按照它的需要工作 我认为它与我的tcpclient的线程有关 如上所述,通过Visual Studio以及常规IIS,我可以通过我的PC上的IIS本地运行良好 部署在一个实际的Windows服务器托管它停止它应该打开一个线程到我的tcpclient类的时间 - 的index.html
<!DOCTYPE html>
<html>
<head>
<script src="scripts/jquery-3.0.0.js"></script>
<script src="scripts/jquery-ui.js"></script>
<link rel="stylesheet" href="scripts/jquery-ui.css">
<link rel="stylesheet" href="wc2.css">
<script src="scripts/jquery.signalR-2.2.0.js"></script>
<!-- this cssfile can be found in the jScrollPane package -->
<link rel="stylesheet" type="text/css" href="jquery.jscrollpane.css" />
<!-- the jScrollPane script -->
<script type="text/javascript" src="scripts/jquery.jscrollpane.min.js"></script>
<script type="text/javascript">
var connection = $.hubConnection();
var hub = connection.createHubProxy("hitCount");
connection.logging = true;
// $.hubConnection().start();
var num = Math.floor(Math.random() * 90000) + 10000;
var Nick = prompt("what is your nickname", "webchat" + num);
var DefaultChannel = "%#the\\blobby";
var mychannel = "";
var myNick = "";
var mygate = "";
var channelWindowCreated = 0;
var isChan_Registered = false;
var ChanModes_set = "";
var isAway = false;
var entityMap = {
"&": "&",
"<": "<",
">": ">",
'"': '"',
"'": ''',
"/": '/'
};
function createChannelWindow(chanWin) {
if (channelWindowCreated == 0) {
var fixChanName = chanWin.replace("%#","").replace("\\b"," ");
$('<div id="lar" class="MainFrame"><div id="leftside" class="chatWindow"></div><div id="rightside"><div id="rBox.'+chanWin+'" class="rightBox"><div id="iBox.'+chanWin+'" class="infoBox"> \
<div id="ChannelText">'+fixChanName+'</div><div id="MemberCount"></div></div><div id="uBox.'+chanWin+'" class="userBox"> \
<p id="dUserNickname"/></div> \
<div id="lBox.'+chanWin+'" class="listBox" oncontextmenu="return false;""><ol id="selectable"></ol></div></div></div></div> \
<div id="bottomside-left"><div class="InputPane"> \
<input id="iInput" type="textbox" class="chatInput" /> \
<input id="iSend" type="submit" class="SendButton" value="Send" /> \
<input type="submit" id="iAction" class="ActionButton" value="!" /> \
</div></div><div id="bottomside-right"><input id="whisperbtn" type="button" /><input id="ignorebtn" type="button" /><input id="checkbtn" type="button" /><input id="profilebtn" type="button" /></div>').appendTo( '#ChannelContainer' );
channelWindowCreated = 1;
}
}
function handle_raws(rawstring) {
var parsed = rawstring.split(" ");
if (parsed[0] == "AUTH") {
var edited_string = rawstring.split(' ').slice(3,4).join(' ');
edited_string = edited_string.replace(":","");
//$('#leftside').append('<div class="ServerNode">' + edited_string + '<br></div>');
}
else if (parsed[0] == "PING") { }
else if (parsed[1] == "PRIVMSG") {
}
else if (parsed[1] == "MODE") {
if (parsed[4] != '') {
}
}
else if (parsed[1] == "800") {
// $('#leftside').append('<div class="ServerNode">' + rawstring.split(' ').slice(2,8).join(' ') + '<br></div>');
}
else if ((parsed[1] == "001") || (parsed[1] == "002") || (parsed[1] == "003") || (parsed[1] == "004") || (parsed[1] == "251") || (parsed[1] == "252" ) || (parsed[1] == "254") || (parsed[1] == "255") || (parsed[1] == "265") || (parsed[1] == "266") || (parsed[1] == "422")) {
edited_string = rawstring.split(' ').slice(3).join(' ');
edited_string = edited_string.replace(":","");
// $('#leftside').append('<div class="ServerNode">' + edited_string + '<br></div>');
}
else if ((parsed[1] == "353") || (parsed[1] == "366") || (parsed[1] == "332") || (parsed[1] == "324") || (parsed[1] == "JOIN") || (parsed[1] == "QUIT")) {
}
else {
// $('#leftside').append('<div class="ServerNode">' + rawstring + '<br></div>');
}
}
function escapeHtml(string) {
return String(string).replace(/[&<>"'\/]/g, function (s) {
return entityMap[s];
});
}
hub.on("onGetNick", function () {
if (myNick == "") {
if (Nick == null) {
Nick = "null" + num;
}
}
else {
Nick = myNick.replace("Guest_", "");
}
});
hub.on("onrecordFixChanName", function (hitCount) {
hitCount = hitCount.replace("%#", "").replace("\\b", " ");
$('#ChannelText').text(hitCount);
$('#ChannelText').addClass("registered_room");
});
hub.on("onStatusUpdate", function (hitCount) {
handle_raws(hitCount);
// $('#leftside').append('<div class="ServerNode">' + hitCount + '<br></div>');
$("#leftside").prop({ scrollTop: $("#leftside").prop("scrollHeight") });
});
hub.on("onChannelUpdate", function (hitCount) {
$('#leftside').append('<div class="ChanNode">' + hitCount + '<br></div>');
$("#leftside").prop({ scrollTop: $("#leftside").prop("scrollHeight") });
});
hub.on("onrecordGate", function (hitCount) {
$('#Gate').text(hitCount);
mygate = hitCount;
});
hub.on("onrecordsetnick", function (setnick) {
$('#setNick').text(setnick);
myNick = setnick;
});
hub.on("onnicklistupdate", function (updatednicklist, nickAmount, nickStatus) {
$('#selectable').html(updatednicklist);
$('#dUserNickname').removeClass();
$('#dUserNickname').addClass(nickStatus);
$('#MemberCount').html(nickAmount + " people chatting");
});
hub.on("onrecordTopicChange", function (topic) {
$('#topic').text(topic);
});
hub.on("onJoinedChannel", function (channel) {
createChannelWindow(channel);
$('#dUserNickname').html('<button id="awaybtn"/>' + myNick);
mychannel = channel;
// $('#rightBox').toggle();
});
hub.on("onRecordHit", function (hitCount) {
$('#hitCountValue').text(hitCount);
});
hub.on("onOpenChatWindow", function () {
});
hub.on("onJoinMessage", function (nickname, message_recieved) {
$('#leftside').append('<div class="JoinNode">' + escapeHtml(message_recieved) + '</div>');
$('#leftside').prop({ scrollTop: $("#leftside").prop("scrollHeight") });
});
hub.on("onChannelMessage", function (nickname, message_recieved) {
$('#leftside').append('<div class="textNode"><span class="nicktext">' + nickname + '</span> : ' + escapeHtml(message_recieved) + '</div>');
$('#leftside').prop({ scrollTop: $("#leftside").prop("scrollHeight") });
});
connection.start().done(function () {
console.log("!!");
hub.invoke('setNick', Nick, DefaultChannel);
// hub.invoke('recordHit');
// createChannelWindow(DefaultChannel);
$('#ChannelContainer').on('keydown', '.chatInput', function (event) {
var keycode = (event.keyCode ? event.keyCode : event.which);
if (keycode == '13') {
if ($('#iInput').val() != "") {
message_sent = $('#iInput').val();
hub.invoke('sendmsg', mychannel, message_sent);
$('#iInput').val("");
$('#leftside').append('<div class="textNode"><strong>' + myNick + '</strong> : ' + escapeHtml(message_sent) + '</div>');
$("#leftside").prop({ scrollTop: $("#lar").prop("scrollHeight") });
}
}
});
$('#iSend').click(function () {
if ($('#iInput').val() != "") {
message_sent = $('#iInput').val();
hub.invoke('sendmsg', mychannel, message_sent);
$('#iInput').val("");
$('#leftside').append('<div class="textNode"><strong>' + myNick + '</strong> : ' + escapeHtml(message_sent) + '</div>');
$("#leftside").prop({ scrollTop: $("#lar").prop("scrollHeight") });
}
});
$('#iAction').click(function () {
if ($('#iInput').val() != "") {
message_sent = $('#iInput').val();
hub.invoke('sendmsg', mychannel, "ACTION " + message_sent + "");
$('#iInput').val("");
$('#leftside').append('<div class="textNode ACTION">' + myNick + ' ' + escapeHtml(message_sent) + '</div>');
$("#leftside").prop({ scrollTop: $("#lar").prop("scrollHeight") });
}
});
$('#awaybtn').click(function () {
if (isAway == false) {
hub.invoke('sendAway', mychannel, "AWAY");
isAway = true;
$('#awaybtn').addClass("active");
}
else {
isAway = false;
hub.invoke('sendAway', mychannel, "");
$('#awaybtn').removeClass("active");
}
});
});
connection.disconnected(function () {
$('#selectable').html("");
$('#leftside').append("<span style='cursor:alias;color: green'>disconnected attempting reconnect...</span><br>");
setTimeout(function () {
connection.start();
}, 5000);
});
</script>
<!--[if IE]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<script>
$(function () {
$("#selectable").bind("mousedown", function (e) {
e.metaKey = true;
}).selectable();
$("#selectable").selectable({
stop: function () {
var result = $("#select-result").empty();
$(".ui-selected", this).each(function () {
var index = $("#selectable li").index(this);
result.append(" #" + (index + 1));
});
}
});
});
</script>
</head>
<body>
<div id="container">
<div id="TopBar">
<header>
<span id="channelName"></span>
<span class="description" id="topic"></span>
<span class="navigate"></span>
</header>
</div>
<div id="Wrapper">
<div id="ServerContainer"></div>
<div id="ChannelContainer"></div>
</div>
</div>
</body>
</html>
hitCounterHub.vb
Imports System.Threading
Imports Microsoft.AspNet.SignalR
Imports Microsoft.AspNet.SignalR.Hubs
Namespace HitCounter
<HubName("hitCount")>
Public Class HitCounterHub
Inherits Hub
Dim WithEvents x As New Connection
Dim dThreads As New Dictionary(Of String, Thread)
Dim MyFormThread As Threading.Thread
Public Shared hitCount As Integer
Public Sub SendMessage(msg As String)
Clients.All.receiveMessge(msg)
End Sub
Public Sub setNick(Nickname As String, Channelz As String)
Dim connId = Me.Context.ConnectionId
x.TempNickProperty = Nickname
x.TempChannelProperty = Channelz
MyFormThread = New Threading.Thread(AddressOf x.Connect)
MyFormThread.IsBackground = True
MyFormThread.Name = "%#testx"
MyFormThread.Start(connId)
End Sub
Public Sub setChannel(Channel As String)
MsgBox(Channel)
Dim connId = Me.Context.ConnectionId
x.TempChannelProperty = Channel
' MsgBox(Nickname)
End Sub
Public Sub sendmsg(channel As String, text As String)
Dim connId = Me.Context.ConnectionId
Dim gx = Connection.Socky("SOCK." + connId)
Dim textc = "PRIVMSG " + channel + " :" + text + vbCrLf
Dim dataz As [Byte]() = System.Text.Encoding.Default.GetBytes(textc)
gx.GetStream.Write(dataz, 0, dataz.Length)
End Sub
Public Sub sendAway(channel As String, text As String)
Dim connId = Me.Context.ConnectionId
Dim gx = Connection.Socky("SOCK." + connId)
Dim textc = "AWAY"
If text = "" Then
textc = textc + vbCrLf
Else
textc = "AWAY " + text + vbCrLf
End If
Dim dataz As [Byte]() = System.Text.Encoding.Default.GetBytes(textc)
gx.GetStream.Write(dataz, 0, dataz.Length)
End Sub
Public Sub RecordHit()
Dim connId = Me.Context.ConnectionId
hitCount = hitCount + 1
Clients.All.onRecordHit(hitCount)
Clients.Client(connId).onOpenChatWindow()
'MyFormThread = New Threading.Thread(AddressOf x.Connect)
'MyFormThread.IsBackground = True
'MyFormThread.Name = "%#lobby"
'MyFormThread.Start(connId)
'hitCount = hitCount + 1
'Clients.All.onRecordHit(hitCount)
End Sub
Public Overrides Function OnConnected() As System.Threading.Tasks.Task
Dim connId = Me.Context.ConnectionId
MessageStatusC(connId, "<span style='cursor:alias;color: green'>Please wait, connecting to server...</span>")
Clients.Client(connId).onGetNick()
Return MyBase.OnConnected()
End Function
Public Overrides Function OnDisconnected(stopCalled As Boolean) As System.Threading.Tasks.Task
Dim connId = Me.Context.ConnectionId
Dim n = Connection.Socky("SOCK." + connId)
n.Close()
hitCount = hitCount - 1
Clients.All.onRecordHit(hitCount)
Return MyBase.OnDisconnected(stopCalled)
End Function
Private Delegate Sub reconnectinvoker(channel As String)
Private Sub tryreconnect(channel As String) Handles x.reconnect
reconnect(channel)
End Sub
Public Sub reconnect(channel As String)
Dim connId = Me.Context.ConnectionId
MyFormThread = New Threading.Thread(AddressOf x.Connect)
MyFormThread.IsBackground = True
MyFormThread.Name = "%#testx"
MyFormThread.Start(connId)
End Sub
End Class
End Namespace
Connection.vb
Imports System.Net.Sockets
Imports System.Collections
Public Class Connection
Private Email As String
Private Pswd As String
Private GKPID As String
Private MSProfile As String
Private MSRegCookie As String
Private MSTicket As String
Private ChatIP As String
Private FindsIp As String
Private PassportAuth As Boolean
Private CustGKID As Boolean
Private GKID As String
Private Ident As String
Private TempNick As String
Private TempChannel As String
Private Nick As String
Private Channel As String
Private AltNick As String
Private VersionReply As String
Private IRC7Version As String
Private FindsFirst As Boolean
Private findsMethodPP As Boolean
Private isitatake As Boolean
Private UserID As String
Public Property UserIDProperty() As String
Get
Return UserID
End Get
Set(ByVal value As String)
UserID = value
End Set
End Property
Public Property isItaTakeProp() As Boolean
Get
Return isItATake
End Get
Set(ByVal value As Boolean)
isItATake = value
End Set
End Property
Public Property TempNickProperty() As String
Get
Return TempNick
End Get
Set(ByVal value As String)
TempNick = value
End Set
End Property
Public Property TempChannelProperty() As String
Get
Return TempChannel
End Get
Set(ByVal value As String)
TempChannel = value
End Set
End Property
Public Property NickProperty() As String
Get
Return Nick
End Get
Set(ByVal value As String)
Nick = value
End Set
End Property
Public Property MSProfileProperty() As String
Get
Return MSProfile
End Get
Set(ByVal value As String)
MSProfile = value
End Set
End Property
Public Property MSTicketProperty() As String
Get
Return MSTicket
End Get
Set(ByVal value As String)
MSTicket = value
End Set
End Property
Public Property MSRegCookieProperty() As String
Get
Return MSRegCookie
End Get
Set(ByVal value As String)
MSRegCookie = value
End Set
End Property
Public Property ChatIPProperty() As String
Get
Return ChatIP
End Get
Set(ByVal value As String)
ChatIP = value
End Set
End Property
Public Property FindsIPProperty() As String
Get
Return FindsIp
End Get
Set(ByVal value As String)
FindsIp = value
End Set
End Property
Public Property IdentProperty() As String
Get
Return Ident
End Get
Set(ByVal value As String)
Ident = value
End Set
End Property
Public Property VersionReplyProperty() As String
Get
Return VersionReply
End Get
Set(ByVal value As String)
VersionReply = value
End Set
End Property
Public Property IRC7VersionProperty() As String
Get
Return IRC7Version
End Get
Set(ByVal value As String)
IRC7Version = value
End Set
End Property
Public Property GKIDProperty() As String
Get
Return GKID
End Get
Set(ByVal value As String)
GKID = value
End Set
End Property
Public Property AUTHPPProperty() As Boolean
Get
Return PassportAuth
End Get
Set(ByVal value As Boolean)
PassportAuth = value
End Set
End Property
Public Property findsMethodPPProperty() As Boolean
Get
Return findsMethodPP
End Get
Set(ByVal value As Boolean)
findsMethodPP = value
End Set
End Property
Public Property FindsFirstProperty() As Boolean
Get
Return FindsFirst
End Get
Set(ByVal value As Boolean)
FindsFirst = value
End Set
End Property
Public Property CustGKIDProperty() As Boolean
Get
Return CustGKID
End Get
Set(ByVal value As Boolean)
CustGKID = value
End Set
End Property
Public Shared Socky As New Dictionary(Of String, TcpClient)
Public Shared Streamy As New Dictionary(Of String, NetworkStream)
Event PowerOn()
Event setOnlineNick(ByVal userid As String, ByVal nickname As String)
Event enterchan(ByVal chan As String)
Event echoStatusC(ByVal userid As String, ByVal response As String)
Event echoStatus(ByVal response As String)
Event echoChannel(ByVal schannel As String, ByVal line As String, ByVal query As String)
Event echoChannelC(ByVal userid As String, ByVal schannel As String, ByVal line As String, ByVal query As String)
Event ChangeTopic(ByVal userid As String, ByVal schannel As String, ByVal response As String)
Event JoinChannel()
Event PartChannel()
Event QuitChannel()
Event ChangeNick(Channel, Nick, newnickname)
Event KillCon(ByVal channel As String)
Event reconnect(Channel)
Event FixChanName(ByVal userid As String, ByVal chan As String)
Event rtrvModes(ByVal schannel As String, ByVal response As String)
Event takefail()
Event wontake()
Event KickChannel()
Event recordGate(ByVal userid As String, ByVal pid As String)
Event getnicklist(ByVal schannel As String, ByVal response As String)
Event UpdateNicklist(ByVal userid As String, ByVal channel As String, ByVal nick As String, ByVal nicklist_AdminArray As List(Of String), ByVal nicklist_ownerArray As List(Of String), nicklist_hostArray As List(Of String) _
, nicklist_VoiceArray As List(Of String), nicklist_UserArray As List(Of String), nicks_Away As List(Of String) _
, Nicks_RegUnknown As List(Of String), Nicks_NoGenderWPic As List(Of String), Nicks_NoGender As List(Of String), Nicks_MaleWPic As List(Of String), Nicks_Male As List(Of String), Nicks_Guest As List(Of String), Nicks_Female As List(Of String), Nicks_FemaleWPic As List(Of String))
Private ChOK As String
'Private Const MSNChatVersionStr As String = "IRCVERS " & SettingsForm.IRCVERSION.Text
Private Const MSNChatAuthenticationInitStr As String = "AUTH GateKeeper I :GKSSP\0r\0\0\0\0\0\0"
Dim MyFormThread As Threading.Thread
Public Sub Connect(ByVal UserID)
RaiseEvent PowerOn()
Try
Dim NicklistArray As New List(Of String)
Dim Nicklist_AdminsArray As New List(Of String)
Dim Nicklist_OwnersArray As New List(Of String)
Dim Nicklist_HostsArray As New List(Of String)
Dim Nicklist_VoicesArray As New List(Of String)
Dim Nicklist_UsersArray As New List(Of String)
Dim Nicks_Away As New List(Of String)
Dim Nicks_Here As New List(Of String)
Dim Nicks_Admin As New List(Of String)
Dim Nicks_Guide As New List(Of String)
Dim Nicks_User As New List(Of String)
Dim Nicks_Male As New List(Of String)
Dim Nicks_MaleWPic As New List(Of String)
Dim Nicks_Female As New List(Of String)
Dim Nicks_FemaleWPic As New List(Of String)
Dim Nicks_NoGender As New List(Of String)
Dim Nicks_NoGenderWPic As New List(Of String)
Dim Nicks_RegUnknown As New List(Of String)
Dim Nicks_Guest As New List(Of String)
Dim Connected As Boolean
Dim Authed As Boolean
Dim Client As New TcpClient
Dim Stream As NetworkStream
Dim server As String
Dim Channel As String = "%#the\blobby"
IRC7Version = "IRC8"
PassportAuth = False
server = "40.77.17.58"
Nick = TempNick
CustGKID = True
Authed = False
Dim GKIDC = HexGate()
Dim PID As String = "*"
Dim port As New Int32
port = "6667"
Client = New TcpClient(server, port)
Dim message As String = "IRCVERS " & IRC7Version & vbLf & MSNChatAuthenticationInitStr & vbCrLf
If PassportAuth = True Then
message = message.Replace("GateKeeper", "GateKeeperPassport")
End If
Dim data As [Byte]() = System.Text.Encoding.UTF8.GetBytes(message)
Stream = Client.GetStream()
If Socky.ContainsKey("SOCK." + UserID) Then
Socky.Remove("SOCK." + UserID)
End If
If Streamy.ContainsKey("stream." + UserID) Then
Streamy.Remove("stream." + UserID)
End If
Socky.Add("SOCK." + UserID, Client)
Streamy.Add("stream." + UserID, Stream)
Stream.Write(data, 0, data.Length)
Dim data2 As [Byte]()
'513 / 700
data2 = New [Byte](4096) {}
Dim responseData As [String] = [String].Empty
Dim bytes As Int32 = Stream.Read(data2, 0, data2.Length)
Dim Feed As String()
'Do While bytes > 0
'Do While Stream.DataAvailable
Do While Stream.CanRead
If Authed = False Then
responseData = System.Text.Encoding.GetEncoding("ISO-8859-1").GetString(data2, 0, bytes)
Else
responseData = System.Text.Encoding.UTF8.GetString(data2, 0, bytes)
' responseData = System.Text.Encoding.GetEncoding("ISO-8859-1").GetString(data2, 0, bytes)
Case Else
End Select
End Select
End If
Next
Threading.Thread.Sleep(10)
bytes = Stream.Read(data2, 0, data2.Length)
Loop
Stream.Close()
Client.Close()
Catch ex As System.Net.Sockets.SocketException
If ex.SocketErrorCode = 10004 Then
Debug.WriteLine("********************************************************************** *****************")
Debug.WriteLine(ex.Message)
Debug.WriteLine("This is normal for the server to complain about, it is the server thread terminating.")
Debug.WriteLine("********************************************************************** *****************")
Else
Debug.WriteLine(ex.Message)
Debug.WriteLine(ex.Source)
Debug.WriteLine(ex.StackTrace)
End If
Catch ex As Exception
End Try
End Sub
End Class
无论如何,这些是3个主要代码 index.html应该用hitcounter启动通信viva signalr
当它收到onNick触发器时,它会打开一个连接到线程的线程。这是它应该连接到网络和通道的地方(它在本地执行此操作)它不会因为某种原因在Windows服务器上执行此操作...谢谢如果你在寻找并告诉我为什么这样做,那么你可以把时间花在任何人身上......是不是有线程问题?