Ronnie
Ronnie
CC#
Created by Ronnie on 6/30/2023 in #help
send a response from TCP server to client
Exception says that objektreference is null Initiates these directly in Form
c#
TcpListener _lyssnare;
TcpClient _klient;
int _port = 12345;
IPAddress _ipAddress = IPAddress.Parse("127.0.0.1");
bool _ärServerIgång;
Kodhanterare _kodhanterare = new Kodhanterare();
c#
TcpListener _lyssnare;
TcpClient _klient;
int _port = 12345;
IPAddress _ipAddress = IPAddress.Parse("127.0.0.1");
bool _ärServerIgång;
Kodhanterare _kodhanterare = new Kodhanterare();
Starts server
c#
public async void StartaServer()
{
try
{
_lyssnare = new TcpListener(_ipAddress, _port);
_lyssnare.Start();
_ärServerIgång = true;


/// <summary>
/// Väntar på meddelande
/// </summary>
try
{
lbl_info.Text = "väntar på koppling...";
_klient = await _lyssnare.AcceptTcpClientAsync();
}
catch (ObjectDisposedException ex)
{
return;
}
lbl_info.Text = "kopplad till klient";
StartaLäsning(_klient);
}
catch (Exception error)
{
MessageBox.Show(error.Message); return;
}
}
c#
public async void StartaServer()
{
try
{
_lyssnare = new TcpListener(_ipAddress, _port);
_lyssnare.Start();
_ärServerIgång = true;


/// <summary>
/// Väntar på meddelande
/// </summary>
try
{
lbl_info.Text = "väntar på koppling...";
_klient = await _lyssnare.AcceptTcpClientAsync();
}
catch (ObjectDisposedException ex)
{
return;
}
lbl_info.Text = "kopplad till klient";
StartaLäsning(_klient);
}
catch (Exception error)
{
MessageBox.Show(error.Message); return;
}
}
Sends back response
c#
public async void StartaSändning(string meddelande)
{
// _klient in here is NULL despite initiated in Form and "used" in StartServer()

byte[] utdata = Encoding.Unicode.GetBytes(meddelande);
try
{
await _klient.GetStream().WriteAsync(utdata, 0, utdata.Length);
}
catch (Exception error)
{ MessageBox.Show(error.Message); return; }
}
c#
public async void StartaSändning(string meddelande)
{
// _klient in here is NULL despite initiated in Form and "used" in StartServer()

byte[] utdata = Encoding.Unicode.GetBytes(meddelande);
try
{
await _klient.GetStream().WriteAsync(utdata, 0, utdata.Length);
}
catch (Exception error)
{ MessageBox.Show(error.Message); return; }
}
17 replies
CC#
Created by Ronnie on 5/26/2023 in #help
Private list problems
23 replies
CC#
Created by Ronnie on 5/26/2023 in #help
String vectors in list? not sure what its called
4 replies
CC#
Created by Ronnie on 3/11/2023 in #help
Class library, cant connect to console app
5 replies
CC#
Created by Ronnie on 3/11/2023 in #help
Forcing user to choose 1, 2 or 3
18 replies
CC#
Created by Ronnie on 3/9/2023 in #help
Can someone explain what the code does step by step?
8 replies
CC#
Created by Ronnie on 12/13/2022 in #help
Search generic list for a searchword
20 replies
CC#
Created by Ronnie on 12/13/2022 in #help
Remove or overwrite single element of list of arrays
11 replies
CC#
Created by Ronnie on 12/12/2022 in #help
❔ Basic question on linear search in list
Hello, I am making a blog/notebook for an assignment and I have a list which contains vectors with 3 elements, title/date/body - i need to do a linear search for a title but I cant find any information on how to loop through the first element on all the vectors in the list, any ideas? Also, i have a DateTime-variable that is declared in the switch function, do i need to declare this at the top before using in Case 1?` Help much appreciated : - P
15 replies