ClientNameという名前のプロパティを持つ新しいクラス継承TcpClientクラスを作成しました。ここでは、このクラスの定義です:は、tcpClientの拡張クラスを持つtcpListenerに接続します。
Try
client = New MyTcpClient(ip, port , "ClientName")
Catch ex As Exception
xUpdate("Can't connect to the server!")
End Try
しかし、私は接続しようとするたびに:私はこのクラスの瞬間を作成し、以下のコードを使用してサーバ(TcpListener)にこのクライアントを接続しようとした
Public Class MyTcpClient
Inherits Net.Sockets.TcpClient
Private _ClintName As String
Sub New(ByVal host As String, ByVal port As Integer, ByVal ClientName As String)
MyBase.New()
_ClintName = ClientName
End Sub
Public Property ClientName()
Get
Return _ClintName
End Get
Set(ByVal value)
_ClintName = value
End Set
End Property
End Class
サーバーに次のエラーメッセージが表示されます。 "System.InvalidOperationException:接続されていないソケットで操作が許可されていません" ここで、MyTcpClientをNet.Socket.TcpClientに変更すると、すべて正常になります。
Try
client = New Net.Socket.TcpClient(ip, port)
Catch ex As Exception
xUpdate("Can't connect to the server!")
End Try
私のクラスのようにれるtcpClientの拡張クラスとTcpListenerに接続する方法はありますか?
フィールドが '_ClientName'である必要がある場合、フィールドは' _ClintName'です。 – jmcilhinney