Ich habe jetzt mal ein bisschen weiter programmiert. Ich denke dass die Nachrichten an den Server gesendet werden, aber da ich nichts vom Server bekomme (ich weiß nicht genau wie ich von einem lokalen Server Nachrichten bekommen kann) kann ich das nicht richtig auf Funktionsfähigkeit testen. Vielleicht hat ja jemand eine Idee???
This commit is contained in:
Binary file not shown.
@@ -2,15 +2,28 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace Connector
|
namespace Connector
|
||||||
{
|
{
|
||||||
class Program
|
class Program
|
||||||
{
|
{
|
||||||
|
static void connect()
|
||||||
|
{
|
||||||
|
Thread t1, t2;
|
||||||
|
Receiver receiver = new Receiver();
|
||||||
|
Sender sender = new Sender();
|
||||||
|
String message = Console.ReadLine();
|
||||||
|
t1 = new Thread(() => receiver.receive());
|
||||||
|
t2 = new Thread(() => sender.send(message));
|
||||||
|
t1.Start();
|
||||||
|
t2.Start();
|
||||||
|
}
|
||||||
|
|
||||||
static void Main(string[] args)
|
static void Main(string[] args)
|
||||||
{
|
{
|
||||||
|
connect();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,13 +10,22 @@ namespace Connector
|
|||||||
{
|
{
|
||||||
class Receiver
|
class Receiver
|
||||||
{
|
{
|
||||||
|
Int32 port = 80;
|
||||||
private TcpClient client;
|
private TcpClient client;
|
||||||
private NetworkStream inStream;
|
private NetworkStream inStream;
|
||||||
|
Byte[] data;
|
||||||
|
|
||||||
public void receive()
|
public void receive()
|
||||||
{
|
{
|
||||||
client = new TcpClient("localhost", 80);
|
client = new TcpClient("localhost", port);
|
||||||
inStream = client.GetStream();
|
inStream = client.GetStream();
|
||||||
|
data = new Byte[256];
|
||||||
|
String responseData = String.Empty;
|
||||||
|
Int32 bytes = inStream.Read(data, 0, data.Length);
|
||||||
|
responseData = System.Text.Encoding.ASCII.GetString(data, 0, bytes);
|
||||||
|
Console.WriteLine("Received: {0}", responseData);
|
||||||
|
inStream.Close();
|
||||||
|
client.Close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,19 +10,23 @@ namespace Connector
|
|||||||
{
|
{
|
||||||
class Sender
|
class Sender
|
||||||
{
|
{
|
||||||
|
Int32 port = 80;
|
||||||
private TcpClient client;
|
private TcpClient client;
|
||||||
private NetworkStream outStream;
|
private NetworkStream outStream;
|
||||||
ASCIIEncoding encoder;
|
Byte[] data;
|
||||||
byte[] buffer;
|
// ASCIIEncoding encoder;
|
||||||
|
// byte[] buffer;
|
||||||
|
|
||||||
public void send(string message)
|
public void send(string message)
|
||||||
{
|
{
|
||||||
buffer = encoder.GetBytes(message);
|
//buffer = encoder.GetBytes(message);
|
||||||
client = new TcpClient("localhost", 80);
|
client = new TcpClient("localhost", port);
|
||||||
|
data = System.Text.Encoding.ASCII.GetBytes(message);
|
||||||
outStream = client.GetStream();
|
outStream = client.GetStream();
|
||||||
message = Console.ReadLine();
|
//message = Console.ReadLine();
|
||||||
outStream.Write(buffer, 0, buffer.Length);
|
outStream.Write(data, 0, data.Length);
|
||||||
outStream.Flush();
|
Console.WriteLine("Sent: {0}", message);
|
||||||
|
outStream.Close();
|
||||||
client.Close();
|
client.Close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user