本文整理汇总了C#中System.Net.Sockets.TcpClient.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# TcpClient.ToString方法的具体用法?C# TcpClient.ToString怎么用?C# TcpClient.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Net.Sockets.TcpClient
的用法示例。
在下文中一共展示了TcpClient.ToString方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SendFile
public static void SendFile(string filePath, string fileName, TcpClient tcpClient)
{
try
{
Console.WriteLine(tcpClient.ToString() + "connected");
NetworkStream networkstream = tcpClient.GetStream();
FileStream fileStream = null;
byte[] _data = new byte[1024];
int _bytesRead = 0;
// _bytesRead = networkstream.Read(_data, 0, _data.Length);
fileStream = new FileStream(filePath+fileName, FileMode.Create, FileAccess.Write, FileShare.ReadWrite);
int byteSize = 0;
byte[] downBuffer = new byte[4096];
int chunkNumber = 0;
while ((byteSize = networkstream.Read(downBuffer, 0, downBuffer.Length)) > 0)
{
chunkNumber++;
Console.WriteLine("ChunkNummer: "+chunkNumber +" transferring : "+byteSize+" bytes");
fileStream.Write(downBuffer, 0, byteSize);
}
networkstream.Close();
fileStream.Close();
Console.ReadKey(true);
}
catch (Exception ex)
{
Console.WriteLine(ex.StackTrace);
Console.ReadKey(true);
}
}
示例2: startListening
public void startListening(int port)
{
try
{
while (_continue)
{
Thread.Sleep(10);
listener = new TcpListener(_ipAddress, port);
listener.Start();
Console.WriteLine("Listening on port " + port);
Console.WriteLine("The local End point is: " + listener.LocalEndpoint);
client = listener.AcceptTcpClient();
Console.WriteLine("Connection accepted from " + client.ToString());
byte[] bytes = new byte[8];
stream = client.GetStream();
stream.Read(bytes, 0, bytes.Length);
_helper.Respond(client, stream, bytes);
StopListening();
}
Console.WriteLine("server stopped");
}
catch (Exception e)
{
Console.WriteLine("Error..... " + e.ToString());
}
}
示例3: ErlConnection
/// <summary>
/// Accept an incoming connection from a remote node
/// </summary>
public ErlConnection(ErlLocalNode node, TcpClient peer)
: base(node, new ErlTcpTransport(peer))
{
_ctor(StringConsts.ERL_CONNECTION.Args(m_Home.NodeName.Value, "<-", peer.ToString()));
}
示例4: Connection
public Connection(TcpClient client, Api.Role role)
: base(new Account(client.ToString(), role)) {
Client = client;
}
示例5: MyTcpServerConnectionClosed
void MyTcpServerConnectionClosed(TcpClient client)
{
listBox1.Items.Add("Closed: " + client.ToString());
}
示例6: DisconnectClient
/// <summary>
/// Removes a given client from our list of clients
/// </summary>
/// <param name="client"></param>
public void DisconnectClient(TcpClient client)
{
if (client == null)
{
return;
}
Console.WriteLine("Disconnected client: " + client.ToString());
client.Close();
clients.Remove(client);
NetworkBuffer buffer;
clientBuffers.TryRemove(client, out buffer);
}
示例7: addNewClient
/// <summary>
///
/// </summary>
/// <param name="p"></param>
/// <param name="incomingClient"></param>
/// <param name="stream"></param>
private void addNewClient(Packet p, TcpClient incomingClient, SslStream stream)
{
clients.Add(p.GetID(), incomingClient);
clientsStreams.Add(p.GetID(), stream);
#region DEBUG
#if DEBUG
Console.WriteLine("ID: " + p.GetID() + "incomingClient: " + incomingClient.ToString());
printClientList();
#endif
#endregion
}
示例8: Fsm
/// <summary>
/// Creates a new instance of DcmULService
/// </summary>
public Fsm(Association assoc, TcpClient s, bool requestor)
{
STA1 = new State1(this, AssociationState.IDLE);
STA2 = new State2(this, AssociationState.AWAITING_READ_ASS_RQ);
STA3 = new State3(this, AssociationState.AWAITING_WRITE_ASS_RP);
STA4 = new State4(this, AssociationState.AWAITING_WRITE_ASS_RQ);
STA5 = new State5(this, AssociationState.AWAITING_READ_ASS_RP);
STA6 = new State6(this, AssociationState.ASSOCIATION_ESTABLISHED);
STA7 = new State7(this, AssociationState.AWAITING_READ_REL_RP);
STA8 = new State8(this, AssociationState.AWAITING_WRITE_REL_RP);
STA9 = new State9(this, AssociationState.RCRS_AWAITING_WRITE_REL_RP);
STA10 = new State10(this, AssociationState.RCAS_AWAITING_READ_REL_RP);
STA11 = new State11(this, AssociationState.RCRS_AWAITING_READ_REL_RP);
STA12 = new State12(this, AssociationState.RCAS_AWAITING_WRITE_REL_RP);
STA13 = new State13(this, AssociationState.ASSOCIATION_TERMINATING);
state = STA1;
this.assoc = assoc;
this.requestor = requestor;
this.s = s;
stream = s.GetStream();
Logger.Info(s.ToString());
ChangeState(requestor ? STA4 : STA2);
}
示例9: BeginSend
public IAsyncResult BeginSend(string host, int port, bool useTls, string callingAe, string calledAe, AsyncCallback callback, object state) {
_client = new TcpClient(host, port);
//zssure:2015-04-14,try to conform whether AddRequest and Send uses the same one client
LogManager.Default.GetLogger("Dicom.Network").Info("zssure debug at 20150414,the TcpClient object is {0},HashCode{1}", _client.ToString(),_client.GetHashCode());
//zssure:2015-04-14,end
if (Options != null)
_client.NoDelay = Options.TcpNoDelay;
else
_client.NoDelay = DicomServiceOptions.Default.TcpNoDelay;
Stream stream = _client.GetStream();
if (useTls) {
var ssl = new SslStream(stream, false, ValidateServerCertificate);
ssl.AuthenticateAsClient(host);
stream = ssl;
}
return BeginSend(stream, callingAe, calledAe, callback, state);
}