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); } }
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()); } }
/// <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())); }
public Connection(TcpClient client, Api.Role role) : base(new Account(client.ToString(), role)) { Client = client; }
void MyTcpServerConnectionClosed(TcpClient client) { listBox1.Items.Add("Closed: " + client.ToString()); }
/// <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); }
/// <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 }
/// <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); }
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); }