TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Muzammil Rajpoot
NA
18
4.9k
Tcplistener/client application
Jan 3 2020 5:51 PM
hello everyone,
I am trying to make 2 different applications on 2 different computers respectively. Moreover i want these applications to communicate over ethernet cable.
The code for receiver application is guven below and unfortunately it is not working. Instead i am getting some error i.e.
"The requested address is not valid in its context"
Making improvements in this code will be prefered instead of links to other sites.
public
sealed
partial
class
MainPage : Page
{
public
MainPage()
{
this
.InitializeComponent();
}
TcpListener Listener;
IPAddress localAddr = IPAddress.Parse(
"192.168.x.xx"
);
Int32 port = Int32.Parse(
"5001"
);
private
void
Recieve_Click(
object
sender, RoutedEventArgs e)
{
Listener =
new
TcpListener(localAddr,port);
Listener.Start();
Byte[] bytes =
new
Byte[256];
String data =
null
;
while
(
true
)
{
IP.Text =
"Waiting for a connection... "
;
// Perform a blocking call to accept requests.
// You could also user server.AcceptSocket() here.
TcpClient client = Listener.AcceptTcpClient();
IP.Text =
"Connected!"
;
// Get a stream object for reading and writing
NetworkStream stream = client.GetStream();
int
i;
// Loop to receive all the data sent by the client.
while
((i = stream.Read(bytes, 0, bytes.Length)) != 0)
{
// Translate data bytes to a ASCII string.
data = System.Text.Encoding.ASCII.GetString(bytes, 0, i);
IP.Text = data;
// Process the data sent by the client.
data = data.ToUpper();
byte
[] msg = System.Text.Encoding.ASCII.GetBytes(data);
// Send back a response.
stream.Write(msg, 0, msg.Length);
// IP.Text = "Sent: {0}";
}
// Shutdown and end connection
client.Close();
}
}
}
}
Reply
Answers (
1
)
Networking Programming Over LAN in UWP
Publishing articles related to windows servers