Thread Socket-Server, ich verstehe es nicht ganz: Perl-Server+C#-Client-> Bi-Direkt.-Verbi (15 answers)
Opened by Gast at 2007-02-20 14:14

no1gizmo
 2007-02-21 12:52
#37471 #37471
User since
2007-02-20
21 Artikel
BenutzerIn
[Homepage] [default_avatar]
[quote=esskar,21.02.2007, 11:40]c#
Code: (dl )
1
2
3
4
foreach (Socket socket in this.socketList)
{
socket.send_stream("Das ist ein Test!\r\n");
}

(send_stream ist ja von dir, oder; wäre interessant zu wissen, wie diese funktion implementiert ist)
[/code][/quote]
Jo, hier meine Socket-Klasse (noch nicht absolut fertig, wie man sieht), hier findet man auch "send_stream()":

Quote
using System;
using System.Collections.Generic;
using System.Text;
using System.Net.Sockets;

namespace TestGUI
{
class Socket
{
private bool connected = false;
TcpClient tcpClient;
NetworkStream nwStream;

string ip_adress = "";
int port;

public string IP
{
get
{
return this.ip_adress;
}
}

public int Port
{
get
{
return this.port;
}
}

public bool Connected
{
get
{
return this.connected;
}
}

public Socket()
{
tcpClient = new TcpClient();
}

public void Exit()
{
tcpClient.Close();
}


public bool connect(string ip, int port)
{
this.ip_adress = ip;
this.port = port;

try
{
tcpClient.Connect(ip, port);
Console.WriteLine("hinbekommen");
}
catch
{
Console.WriteLine("Verbindung fehlgeschlagen");
this.connected = false;
}
try
{
nwStream = tcpClient.GetStream();
this.connected = true;
}
catch
{
this.connected = false;
}

return this.connected;

}

public void disconnect()
{
this.tcpClient.Close();
this.connected = false;
}

public string get_stream()
{
string returndata = "";

if (this.connected)
{
byte[] bytes = new byte[tcpClient.ReceiveBufferSize];

try
{
nwStream.Read(bytes, 0, (int)tcpClient.ReceiveBufferSize);
}
catch
{
}
returndata = Encoding.ASCII.GetString(bytes);
}

return returndata;
}

public void send_stream(string senddata)
{
if (this.connected)
{
Byte[] sendBytes = Encoding.ASCII.GetBytes(senddata);

try
{
nwStream.Write(sendBytes, 0, sendBytes.Length);
}
catch
{

}
}
}
}
}

View full thread Socket-Server, ich verstehe es nicht ganz: Perl-Server+C#-Client-> Bi-Direkt.-Verbi