Leser: 1
![]() |
|< 1 2 >| | ![]() |
16 Einträge, 2 Seiten |
1
2
3
4
foreach (object socket in this.socketList)
{
((Socket)socket).send_stream("Das ist ein Test!"+'\r'+'\n');
}
1
2
3
4
foreach (Socket socket in this.socketList)
{
socket.send_stream("Das ist ein Test!\r\n");
}
Quoteusing 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
{
}
}
}
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
using System;
using System.Text;
using System.Net;
using System.Net.Sockets;
namespace Esskar {
public class TcpSocket : Socket
{
public TcpSocket()
: base(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp) { }
public void Bind(IPAddress address, int port)
{
Bind(new IPEndPoint(address, port));
}
public void Listen()
{
Listen(5);
}
public int Send(string str) {
return this.Send(str, Encoding.ASCII);
}
public int Send(string str, Encoding enc) {
byte[] sendBytes = enc.GetBytes(str);
return this.Send(sendBytes);
}
}
}
![]() |
|< 1 2 >| | ![]() |
16 Einträge, 2 Seiten |