Advertisement
Guest User

Untitled

a guest
May 11th, 2014
316
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.57 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Net.Sockets;
  7. using System.Net;
  8. using System.IO;
  9.  
  10. namespace ConsoleApplication4
  11. {
  12.     class Program
  13.     {
  14.         static Socket doidaco;
  15.            
  16.            static  TcpListener tccp;
  17.             static NetworkStream newton;
  18.             static BinaryReader rr ;
  19.         static void Main(string[] args)
  20.         {
  21.             Console.ForegroundColor = ConsoleColor.Yellow;
  22.             try
  23.             {
  24.                  Console.WriteLine("Iniciando...");
  25.                  IPEndPoint ipp = new IPEndPoint(IPAddress.Parse("192.168.173.1"), 5000);
  26.                 tccp=new TcpListener(ipp);
  27.                 tccp.Start();
  28.                 Console.WriteLine("Conexão TCP iniciada, ip : 127.0.0.1, porta: 4567");
  29.  
  30.                 doidaco = tccp.AcceptSocket();
  31.                 newton = new NetworkStream(doidaco);
  32.                 rr = new BinaryReader(newton);
  33.  
  34.                 string mensagem="";
  35.                 do{
  36.                      mensagem = rr.ReadString();
  37.                     Console.WriteLine("\nMensagem do cliente: "+mensagem);
  38.  
  39.                 }while(doidaco.Connected);
  40.  
  41.  
  42.                
  43.            
  44.             }
  45.             catch(Exception e){
  46.                 Console.WriteLine("Erro: "+e.Message);
  47.                 Console.ReadKey();
  48.             }
  49.             finally
  50.             {
  51.                 doidaco.Close();
  52.                 rr.Close();
  53.                 newton.Close();
  54.             }
  55.         }
  56.     }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement