Probably simple problem with networking
- From: "Tomas Machala" <t.machala@xxxxxxxxxx>
- Date: Tue, 23 Aug 2005 15:50:07 +0200
using
System;using System.IO;
using System.Text;
using System.Net;
using System.Net.Sockets;
namespace
NetPokus
{
class NetPokus
{
[STAThread]
{
string recv;
Odpovedi odp;
try
{
odp = new Odpovedi();
}
catch (SocketException
ex)
{
Console.WriteLine(ex.ToString());
Console.ReadLine();
return;
}
while (true)
{
odp.Write("Waiting for
command\n");
recv = odp.Read();
if (recv ==
"exit")
{
break;
}
else
{
Console.Write(recv);
}
}
odp.Close();
}
}
public class
Odpovedi
{
TcpClient
client;
NetworkStream nstr;
byte[] received;
byte[] toSend;
public
Odpovedi()
{
client = new TcpClient("127.0.0.1", 1234);
nstr
= client.GetStream();
}
public void Write(string
msg)
{
toSend = Encoding.ASCII.GetBytes(msg);
nstr.Write(toSend, 0, toSend.Length);
}
public string
Read()
{
received = new byte[client.ReceiveBufferSize];
nstr.Read(received, 0, client.ReceiveBufferSize);
return
Encoding.ASCII.GetString(received);
}
public void
Close()
{
client.Close();
}
}
}
- Follow-Ups:
- Re: Probably simple problem with networking
- From: Nick Malik [Microsoft]
- Re: Probably simple problem with networking
- From: Helge Jensen
- Re: Probably simple problem with networking
- Prev by Date: Re: Reentrant (?) Console Application....
- Next by Date: .NET Script Hosting and events
- Previous by thread: WINSERVICE TIMER
- Next by thread: Re: Probably simple problem with networking
- Index(es):
Relevant Pages
|