I read a lot on web but could not successfully send and receive message while connection established correctly using socket programming. one of the simple code is following, Actually, my task is: I have to make connection with server as I have IP and port and I have to send specific message to server; based on this message, server will reply. I want to know how to do it and in what sequence ?
I also tried some other codes in which SocketSreamListener
used but its event never raised. I also want to know if I use this listener.BindServiceNameAsync("?")
then what should I pass into it and what are ports for windows phone on which I should listen etc
var socket = new StreamSocket();
var writer = new DataWriter(socket.OutputStream);
var reader = new DataReader(socket.InputStream);
await socket.ConnectAsync(new HostName("server ip"), "port")
writer.WriteString("specific msg");
await writer.StoreAsync();
var bytesRead = await reader.LoadAsync(300000);
var response = reader.ReadString(bytesRead);
I will be very thankful as I am stuck and could not get help. I am also unable to debug above code because when I reach reader.LoadAsync
then control never returns to next line, I waited alot