Jump to content
Xtreme .Net Talk

JumpyNET

Avatar/Signature
  • Posts

    196
  • Joined

  • Last visited

Everything posted by JumpyNET

  1. A simplified version of the MSDN StreamSocket sample (tested and working). TCP Client (Windows Phone 8 App) Imports Windows.Networking Imports Windows.Networking.Sockets Imports Windows.Storage.Streams Partial Public Class MainPage : Inherits PhoneApplicationPage Dim Socket As StreamSocket Private Async Sub ButtonConnect_Click(sender As Object, e As RoutedEventArgs) Handles ButtonConnect.Click Socket = New StreamSocket Await Socket.ConnectAsync(New HostName("192.168.1.7"), "1234") StartListening() End Sub Private Async Sub StartListening() Dim reader As New DataReader(Socket.InputStream) Do ' Read first 4 bytes (length of the subsequent string). Dim sizeFieldCount As UInteger = Await reader.LoadAsync(CUInt(Runtime.InteropServices.Marshal.SizeOf(New UInteger))) If sizeFieldCount <> Runtime.InteropServices.Marshal.SizeOf(New UInteger) Then ' The underlying socket was closed before we were able to read the whole data. Return End If ' Read the string. Dim stringLength As UInteger = reader.ReadUInt32() Dim actualStringLength As UInteger = Await reader.LoadAsync(stringLength) If stringLength <> actualStringLength Then ' The underlying socket was closed before we were able to read the whole data. Return End If ' Display the string. Dim MsgReceived As String = reader.ReadString(actualStringLength) System.Diagnostics.Debug.WriteLine(MsgReceived) Loop End Sub Private Async Sub ButtonSend_Click(sender As Object, e As RoutedEventArgs) Handles ButtonSend.Click Dim stringToSend As String = "Some Text To Send" Dim writer As New DataWriter(Socket.OutputStream) writer.WriteUInt32(writer.MeasureString(stringToSend)) writer.WriteString(stringToSend) Await writer.StoreAsync() writer.DetachStream() writer.Dispose() End Sub End Class TCP Server (Windows 8 Store App) Imports Windows.Networking Imports Windows.Networking.Sockets Imports Windows.Storage.Streams Public NotInheritable Class MainPage : Inherits Page Dim WithEvents ListenerSocket As StreamSocketListener Private Async Sub ButtonListen_Click(sender As Object, e As RoutedEventArgs) Handles ButtonListen.Click ListenerSocket = New StreamSocketListener ' Don't limit traffic to an address or an adapter. Await ListenerSocket.BindServiceNameAsync("1234") End Sub Dim Socket As StreamSocket Private Async Sub listener_ConnectionReceived(sender As StreamSocketListener, args As StreamSocketListenerConnectionReceivedEventArgs) Handles ListenerSocket.ConnectionReceived ' Invoked once a connection is established. Debug.WriteLine("Connection Established") Socket = args.Socket Dim reader As New DataReader(args.Socket.InputStream) Do ' Read first 4 bytes (length of the subsequent string). Dim sizeFieldCount As UInteger = Await reader.LoadAsync(CUInt(Runtime.InteropServices.Marshal.SizeOf(New UInteger))) If sizeFieldCount <> Runtime.InteropServices.Marshal.SizeOf(New UInteger) Then Return ' The underlying socket was closed before we were able to read the whole data. End If ' Read the string. Dim stringLength As UInteger = reader.ReadUInt32() Dim actualStringLength As UInteger = Await reader.LoadAsync(stringLength) If stringLength <> actualStringLength Then Return ' The underlying socket was closed before we were able to read the whole data. End If ' Display the string. Dim MsgReceived As String = reader.ReadString(actualStringLength) Debug.WriteLine(MsgReceived) Loop End Sub Private Async Sub ButtonSend_Click(sender As Object, e As RoutedEventArgs) Handles ButtonSend.Click Dim stringToSend As String = "Some Text Back" Dim writer As New DataWriter(Socket.OutputStream) writer.WriteUInt32(writer.MeasureString(stringToSend)) writer.WriteString(stringToSend) Await writer.StoreAsync() writer.DetachStream() writer.Dispose() End Sub End Class PS: Requesting to be moved to code library, please.
  2. I am a hobbyist programmer. I have been using Visual Basic 2008 Express for all these years. I never got used to any of the more modern versions of Visual Studio. Windows Phone was an exception, though one short lived. I have been educating my self to move to the GNU/Linux world, but it has proven difficult to find a programming language and an integrated development environment as good as Visual Basic 2008 Express. I am open to suggestions if any of you might have any?
  3. The text "oletus" is show when the app is run on the phone or the emulator. What should I change so that the text is shown on design time as well? Please see the attached screenshot for xaml and code behind.
  4. A simplified version of the MSDN StreamSocket sample (tested and working). TCP Client (Windows Phone 8 App) Imports Windows.Networking Imports Windows.Networking.Sockets Imports Windows.Storage.Streams Partial Public Class MainPage : Inherits PhoneApplicationPage Dim Socket As StreamSocket Private Async Sub ButtonConnect_Click(sender As Object, e As RoutedEventArgs) Handles ButtonConnect.Click Socket = New StreamSocket Await Socket.ConnectAsync(New HostName("192.168.1.7"), "1234") StartListening() End Sub Private Async Sub StartListening() Dim reader As New DataReader(Socket.InputStream) Do ' Read first 4 bytes (length of the subsequent string). Dim sizeFieldCount As UInteger = Await reader.LoadAsync(CUInt(Runtime.InteropServices.Marshal.SizeOf(New UInteger))) If sizeFieldCount <> Runtime.InteropServices.Marshal.SizeOf(New UInteger) Then ' The underlying socket was closed before we were able to read the whole data. Return End If ' Read the string. Dim stringLength As UInteger = reader.ReadUInt32() Dim actualStringLength As UInteger = Await reader.LoadAsync(stringLength) If stringLength <> actualStringLength Then ' The underlying socket was closed before we were able to read the whole data. Return End If ' Display the string. Dim MsgReceived As String = reader.ReadString(actualStringLength) System.Diagnostics.Debug.WriteLine(MsgReceived) Loop End Sub Private Async Sub ButtonSend_Click(sender As Object, e As RoutedEventArgs) Handles ButtonSend.Click Dim stringToSend As String = "Some Text To Send" Dim writer As New DataWriter(Socket.OutputStream) writer.WriteUInt32(writer.MeasureString(stringToSend)) writer.WriteString(stringToSend) Await writer.StoreAsync() writer.DetachStream() writer.Dispose() End Sub End Class TCP Server (Windows 8 Store App) Imports Windows.Networking Imports Windows.Networking.Sockets Imports Windows.Storage.Streams Public NotInheritable Class MainPage : Inherits Page Dim WithEvents ListenerSocket As StreamSocketListener Private Async Sub ButtonListen_Click(sender As Object, e As RoutedEventArgs) Handles ButtonListen.Click ListenerSocket = New StreamSocketListener ' Don't limit traffic to an address or an adapter. Await ListenerSocket.BindServiceNameAsync("1234") End Sub Dim Socket As StreamSocket Private Async Sub listener_ConnectionReceived(sender As StreamSocketListener, args As StreamSocketListenerConnectionReceivedEventArgs) Handles ListenerSocket.ConnectionReceived ' Invoked once a connection is established. Debug.WriteLine("Connection Established") Socket = args.Socket Dim reader As New DataReader(args.Socket.InputStream) Do ' Read first 4 bytes (length of the subsequent string). Dim sizeFieldCount As UInteger = Await reader.LoadAsync(CUInt(Runtime.InteropServices.Marshal.SizeOf(New UInteger))) If sizeFieldCount <> Runtime.InteropServices.Marshal.SizeOf(New UInteger) Then Return ' The underlying socket was closed before we were able to read the whole data. End If ' Read the string. Dim stringLength As UInteger = reader.ReadUInt32() Dim actualStringLength As UInteger = Await reader.LoadAsync(stringLength) If stringLength <> actualStringLength Then Return ' The underlying socket was closed before we were able to read the whole data. End If ' Display the string. Dim MsgReceived As String = reader.ReadString(actualStringLength) Debug.WriteLine(MsgReceived) Loop End Sub Private Async Sub ButtonSend_Click(sender As Object, e As RoutedEventArgs) Handles ButtonSend.Click Dim stringToSend As String = "Some Text Back" Dim writer As New DataWriter(Socket.OutputStream) writer.WriteUInt32(writer.MeasureString(stringToSend)) writer.WriteString(stringToSend) Await writer.StoreAsync() writer.DetachStream() writer.Dispose() End Sub End Class PS: Requesting to be moved to code library, please.
  5. I have put up a simple DatagramSocket test example with separate solutions/projects for client and server. Sending strings from client to server is working but sending a string from server to client results in the following error: "A method was called at an unexpected time. (Exception from HRESULT: 0x8000000E)" What could be the problem ??? Source code for the UDP Client (Windows Phone 8 App) Partial Public Class MainPage : Inherits PhoneApplicationPage Dim WithEvents Soketti As DatagramSocket Private Async Sub ButtonConnect_Click(sender As Object, e As RoutedEventArgs) Handles ButtonConnect.Click Soketti = New DatagramSocket Await Soketti.ConnectAsync(New HostName("192.168.1.7"), "4321") End Sub Private Sub Soketti_MessageReceived(sender As DatagramSocket, args As DatagramSocketMessageReceivedEventArgs) Handles Soketti.MessageReceived Dim reader As DataReader = args.GetDataReader Dim actualStringLength As UInteger = reader.UnconsumedBufferLength Dim MsgReceived As String = reader.ReadString(actualStringLength) System.Diagnostics.Debug.WriteLine(MsgReceived) End Sub Private Async Sub ButtonSend_Click(sender As Object, e As RoutedEventArgs) Handles ButtonSend.Click Dim stringToSend As String = "Some Text To Send" Dim writer As New DataWriter(Soketti.OutputStream) writer.WriteString(stringToSend) Await writer.StoreAsync() writer.DetachStream() writer.Dispose() End Sub End Class Source code for the UDP Server (Windows 8.0 Store App) Public NotInheritable Class MainPage : Inherits Page Dim WithEvents not_just_a_listener As DatagramSocket Private Async Sub ButtonListen_Click(sender As Object, e As RoutedEventArgs) Handles ButtonListen.Click not_just_a_listener = New DatagramSocket Await not_just_a_listener.BindServiceNameAsync("4321") End Sub Private Sub listener_MessageReceived(sender As DatagramSocket, args As DatagramSocketMessageReceivedEventArgs) Handles not_just_a_listener.MessageReceived Dim reader As DataReader = args.GetDataReader Dim actualStringLength As UInteger = reader.UnconsumedBufferLength Dim MsgReceived As String = reader.ReadString(actualStringLength) Debug.WriteLine(MsgReceived) End Sub Private Async Sub ButtonSend_Click(sender As Object, e As RoutedEventArgs) Handles ButtonSend.Click Dim stringToSend As String = "Some Text Back" Dim writer As New DataWriter(not_just_a_listener.OutputStream) writer.WriteString(stringToSend) Await writer.StoreAsync() ' ** This will crash *** writer.DetachStream() writer.Dispose() End Sub End Class
  6. What would be the best way to do the following in XAML? <StackPanel Grid.Row=IIF(Orientation="Portrait","2","1") Grid.Column=IIF(Orientation="Portrait","0","2") > ------------------------------------------------------------------------ At first I was thinking of using a ValueConverter but they do not seem to support multiple parameters. I guess passing both of the parameters in a single string such as "2|1" (which I would them split in my ValueConverter) would be bad practice, I was wondering could it be possible to do something like the following? <StackPanel Grid.Row="{Binding Orientation, ConverterParameter=[[new CustomClass(2,0)]], Converter={StaticResource OrientationToIntegerConverter}, ElementName=phoneApplicationPage}" Grid.Column="{Binding Orientation, ConverterParameter=[[new CustomClass(1,2)]], Converter={StaticResource OrientationToIntegerConverter}, ElementName=phoneApplicationPage}" >
  7. Issue Solved After configuring all the computers in windows control panel pinging them started working also. No modifications to F-secure or the router was done or required.
  8. I am having trouble setting up my local home network for remote debugging a surface tablet. Ping requests to all the local addresses (192.168.1.*) except the adsl-modem-wifi-router get timed out. A ideas how to get the network working?
  9. I am trying to convert the C# LongListSelectorSample from http://phone.codeplex.com/ to VisualBasic. Here is the original C# code (with the problematic linq-query included): private void LoadLinqMovies() { List<Movie> movies = new List<Movie>(); for (int i = 0; i < 50; ++i) { movies.Add(Movie.CreateRandom()); } var moviesByCategory = from movie in movies group movie by movie.Category into c orderby c.Key select new PublicGrouping<string, Movie>(c); linqMovies.ItemsSource = moviesByCategory; } And here is my VB attempt to populate the LongListSelector with grouped movie items: Private Sub LoadLinqMovies() Dim MovieList As New List(Of Movie) For i As Integer = 0 To 49 MovieList.Add(Movie.CreateRandom()) Next Dim MoviesByCategory = _ From OneMovie In MovieList _ Group OneMovie By Cat = OneMovie.Category _ Into GroupedMovies = Group _ Select New PublicGrouping(Of String, Movie)(GroupedMovies) Movies_LLS.ItemsSource = MoviesByCategory End Sub Apparently something goes wrong with the linq query but what?
  10. RichTextBox does support TextAlignment="Justify".
  11. I cannot seem to find any way to change priority of threads on the Windows Phone 8 platform. The default priority seems to be too high as my app takes now 2,5 seconds to startup, but if I make my background thread sleep alot the startup time will be only 0,8 seconds. Any advice?
  12. How can I replace text inside angle brackets? My best try so far: Dim Input As String = "Aaaa [abc] Bbbb [7] Ccc" Dim Output As String = Regex.Replace(Input, "\[.+\]\s", "") ' Output is "Aaaa Ccc" but should be "Aaaa Bbbb Ccc"
  13. Is there any way to get Justified TextAlignment on Windows Phone? At least TextBlock does not seem to support that. Is it possible to somehow use Silverlight components or do you know if some one has made a custom TextBlock?
  14. Your thorough response is much appreciated. Thank you.
  15. Googling for instructions spesific to Windows Phone seems impossible. Can someone please help me how to replace the following VB-code with WP alternatives? Dim Beginning As String = Left("Some Text", 2) Dim Answer As Boolean = "Some Text" Like "S*"
  16. Whenever following tutorials I seem to get stuck with the simplest things that the makers of the tutorials decided to omit. Adding a reference to "Web.Extensions" did the trick. So thank you very much!
  17. What references do I need to add to get this working? Imports System.Web.Script.Serialization
  18. Seeing just the UI part was not quite the thing I had in mind. The idea was that studying the whole code could be good for learning XAML. I just found this free tool called ILSpy, which is able to show the VB code behind System.Windows.Controls.Label. I just don't know how to find the XAML "equivalent".
  19. One solution could be a USB virtual COM-port. This is a common practice for communication between a micro-controller and a PC. 1) System.IO.Ports.SerialPort should be fairly easy to use. 2) I have no experiece setting up a virtual COM-port but you could try googling for advice on that.
  20. I am trying to study WPF and was wondering if it is possible to examine the XAML or "source code" behind the "native" elements such as Label. PS: I am using Visual Studio Professional 2012.
  21. Thank you. This could be a wise decision from the VS team. Could you (or some one else) please recommend a free conversion solution? The 3D models I am currently looking to test are *.OSG and *.3DS.
  22. What are the 3D-file-formats supported by WPF in VS2012?
  23. Thank you snarfblam! Actually I had already googled the site you suggested. I wanted to leave more choice for the one answering my question as I just wasn't sure they did everything in the best possible way. But if you vouch for the code sample I gues it's a proper way to do it. My main problem was figuring out how to have my code access back to Form1. I'm sorry for not achieving to explain this in my original question. Anyway after seeing this piece of code frm as WindowsApplication1.Form1 I got back on track. Thanks!
  24. I would like to compile and execute code at runtime and access the main form from the runtime code. Public Class Form1 Public TestVariable As Integer = 7 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load ExecuteTxtCode("Form1.TestVariable = 2") 'How should I alter this???? Me.Text = TestVariable 'Should be 2 and not the initial value of 7. End Sub Private Sub ExecuteTxtCode(ByVal Code As String) 'What should I put here???? End Sub End Class
  25. Unlocked Windows Phone 7 for Programming Thank you dotnetguy, this truly seems to be the case. Although students need not pay a dime. What a relief. I got everything up and running. Here are the steps: 1) The download for "Visual Studio 2010 Express for Windows Phone ISO" is available here. Get it and install it. 2) You also need "Zune Software" available here. Apparently it is not just a program used to transfer music to your phone. Get it, install it and keep it running on the background. 3) Create a student account at Dreamspark. The navigate to: "Developer & Designer Tools" --> "Windows Phone and App Hub" and go through two of the last steps: 2."Map your Live ID", 3."Register on AppHub" 4) Navigate to "C:\Program Files (x86)\Microsoft SDKs\Windows Phone\v7.1\Tools\Phone Registration\", run "PhoneReg.exe" and type in your account details created in step 3. Now your phone should be unlocked for development. So if you use another computer for programming you only need to have VS and Zune on it and it does not check for the AppHub subscription anymore.
×
×
  • Create New...