CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Nov 2013
    Location
    Pennsyvania, USA
    Posts
    28

    [Solved] Communicating via Sockets?

    I'm currently attempting to pass information to a Raspberry Pi from a Notebook computer via computer files using Streamwriter
    (see this thread: How to use Streamwriter to write a file to another computer on a network?)

    But I also heard that using Sockets is a better way to communicate with another computer. I have no experience with Sockets. Can anyone explain what a Socket is, and how it might be used:

    I program in the Notebook using C#.
    I program on the Raspberry Pi using Python.
    Both the Notebook and the Raspberry Pi have WiFi and are currently set up to change files using File Explorer.

    How would I go about setting up a Socket to connect these two computers? Do I need to write a Socket program on each device that connect to each other?

    I have no clue about Sockets or where to begin. I was told that they are a good way to communicate between two computers via WiFi.

    For my purposes if I can just exchange simple text files between these two computers that would work for me. This is why I'm looking at using Streamreader and Streamwriter.

    But I'd like to learn about Sockets too now that people are saying that Sockets are a good way to do this.

    Thanks

    P.S. I'm also open to any other alternative methods. My main goal is to be able to exchange just a few English text words between these two computers. That's all I really need to do for my purposes. I don't really need a major continuous bitstream connection. Although something like that might come in handy at a later date for exchanging large files or whatever.
    Last edited by Leucippus; February 23rd, 2018 at 07:11 AM.
    In C# I use SharpDevelop IDE ver 4.4.1 and .NET version 4.0 (OS is Windows 7)
    In Python I use Geany IDE on a Raspberry Pi (OS is Raspbian)
    I'm also learning C and C++
    My main use of programming is for Robotics and AI.

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Communicating via Sockets?

    Try searching the internet for "c# socket example".

  3. #3
    Join Date
    Nov 2013
    Location
    Pennsyvania, USA
    Posts
    28

    Re: Communicating via Sockets?

    Quote Originally Posted by Arjay View Post
    Try searching the internet for "c# socket example".
    Thanks, that actually produced the best example yet. It's not that I wasn't already searching. I certainly was. But I kept coming up with extremely complex examples that seemed to be way more information than I needed, or weren't very well explained. I was also searching on YouTube and kept finding extremely complex tutorials that seemed to assume a lot of information.

    By typing "C# socket example" into Google as you suggested I came up with the following example that appears to be pretty easy to follow. Plus they even have example code that can be copied and pasted directly into the C# IDE.

    Here's the example I found:

    Net-informations.com How to C# Socket programming

    This appears to be one of the most straight-forward examples I've found yet.

    None the less using sockets appears to be way more complicated than using StreamWriter for just sending a few commands to another computer. It's no doubt something worth learning though.
    In C# I use SharpDevelop IDE ver 4.4.1 and .NET version 4.0 (OS is Windows 7)
    In Python I use Geany IDE on a Raspberry Pi (OS is Raspbian)
    I'm also learning C and C++
    My main use of programming is for Robotics and AI.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured