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.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Connector
|
||||
{
|
||||
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)
|
||||
{
|
||||
|
||||
connect();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,13 +10,22 @@ namespace Connector
|
||||
{
|
||||
class Receiver
|
||||
{
|
||||
Int32 port = 80;
|
||||
private TcpClient client;
|
||||
private NetworkStream inStream;
|
||||
Byte[] data;
|
||||
|
||||
public void receive()
|
||||
{
|
||||
client = new TcpClient("localhost", 80);
|
||||
client = new TcpClient("localhost", port);
|
||||
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
|
||||
{
|
||||
Int32 port = 80;
|
||||
private TcpClient client;
|
||||
private NetworkStream outStream;
|
||||
ASCIIEncoding encoder;
|
||||
byte[] buffer;
|
||||
Byte[] data;
|
||||
// ASCIIEncoding encoder;
|
||||
// byte[] buffer;
|
||||
|
||||
public void send(string message)
|
||||
{
|
||||
buffer = encoder.GetBytes(message);
|
||||
client = new TcpClient("localhost", 80);
|
||||
//buffer = encoder.GetBytes(message);
|
||||
client = new TcpClient("localhost", port);
|
||||
data = System.Text.Encoding.ASCII.GetBytes(message);
|
||||
outStream = client.GetStream();
|
||||
message = Console.ReadLine();
|
||||
outStream.Write(buffer, 0, buffer.Length);
|
||||
outStream.Flush();
|
||||
//message = Console.ReadLine();
|
||||
outStream.Write(data, 0, data.Length);
|
||||
Console.WriteLine("Sent: {0}", message);
|
||||
outStream.Close();
|
||||
client.Close();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user