IT Community - Software Programming, Web Development and Technical Support

socket programming

This is a discussion on socket programming within the VB.NET Programming forums, part of the Software Development category; hi, I have already some experience with socket programming. But now I would like to use socket programming for a ...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Software Development > VB.NET Programming

Register FAQ Members List Calendar Mark Forums Read
  1 links from elsewhere to this Post. Click to view. #1 (permalink)  
Old 09-05-2007, 05:42 AM
amansundar amansundar is offline
D-Web Analyst
 
Join Date: May 2007
Posts: 322
amansundar is on a distinguished road
Default socket programming

hi,

I have already some experience with socket programming. But now I would like to use socket
programming for a Bluetooth connection. Does anybody know how to do this? I’ve done it before
for a wired network, and then you just had to use a tcpClient and a tcpListener, and in the client
program you just had to give in the ip address of the computer where you had your server program
and it worked. But how is this for Bluetooth and pocket devices? Do you also have to use a tcpClient
and tcpListener? Or is it totally different? And what do you have to use in stead of the IP address? My
program language is VB.NET, but it doesn’t matter if it’s a C# example.

Thanks

Last edited by amansundar : 09-05-2007 at 11:09 PM.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 09-05-2007, 06:32 AM
mobilegeek mobilegeek is offline
D-Web Analyst
 
Join Date: Jun 2007
Posts: 205
mobilegeek is on a distinguished road
Smile Re: socket programming

Hi aman,
WInsock is pretty much the same because it represents an abstraction layer that is beyond the physical properties of the data transfer. There are several good tutorials on Winsock-based BTH programming. This one contains a C/C++ sample which is pretty strightforward. Notice for example a server socket is created:

SOCKET s = socket (AF_BT, SOCK_STREAM, BTHPROTO_RFCOMM);
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 09-05-2007, 06:38 AM
amansundar amansundar is offline
D-Web Analyst
 
Join Date: May 2007
Posts: 322
amansundar is on a distinguished road
Default Re: socket programming

Hi,

Thanks for you quick answer, but do you also have a VB.NET example? Is it possible with VB.NET?
I'm not a VB expert exactly so I don't know if it's feasible in VB. However, I'll ask some of the VB experts if they have any samples.
Thank you very much!!!!!
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 09-05-2007, 06:43 AM
krishnakumar krishnakumar is offline
D-Web Analyst
 
Join Date: May 2007
Posts: 206
krishnakumar is on a distinguished road
Cool Re: socket programming

Hi,
Nice to know you too are working in something that i need...i m java developer.....My project includes the development of a GUI in VC++ environment that will connect two Bluetooth enabled computers and allow them to communicate..im currently learning VC++ and Winsock...but i dont know how to proceed next....how to incorporate the Bluetooth functionaliy...im really in a fix cuz i have to finish the project at avery short notice...could you plz guide me on how to proceed further..like what should be the necessary steps....
__________________
Krishnakumar.S
Beware of Everything -that is un true; stick to the Truth shall succeed slowly but steadily
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 09-05-2007, 07:10 AM
amansundar amansundar is offline
D-Web Analyst
 
Join Date: May 2007
Posts: 322
amansundar is on a distinguished road
Default Re: socket programming

What I would do is look for an existing, simple but working project and try to learn from the code how
the BT functionality is used.
__________________
cheers
Aman
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 09-05-2007, 07:13 AM
krishnakumar krishnakumar is offline
D-Web Analyst
 
Join Date: May 2007
Posts: 206
krishnakumar is on a distinguished road
Default Re: socket programming

great ..but where do i get that???
__________________
Krishnakumar.S
Beware of Everything -that is un true; stick to the Truth shall succeed slowly but steadily
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 09-05-2007, 07:14 AM
amansundar amansundar is offline
D-Web Analyst
 
Join Date: May 2007
Posts: 322
amansundar is on a distinguished road
Default Re: socket programming

Hello everybody!

I'm trying to develop a Bluetooth application using winsocks, but my problem is that i cannot create the socket.
When I execute "socket(AF_BTH, SOCK_STREAM, BTHPROTO_RFCOMM)"
the application falls with the next error : 10047 (WSAEAFNOSUPPORT => An address incompatible with the requested protocol was used.)

I have the next include's:
#include <winsock2.h>
#include <Ws2bth.h>
#include <BluetoothAPIs.h>

Should I need to add something else to my project?, or maybe should I need change some configuration properties on my operating system?

Thanks.
__________________
cheers
Aman
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 09-05-2007, 07:18 AM
saloni srivatsava saloni srivatsava is offline
D-Web Trainee
 
Join Date: Sep 2007
Posts: 16
saloni srivatsava is on a distinguished road
Default Re: socket programming

anyone plz help me out with following ques..it's needed for my interview process

What is Socket Programming-


What are its functions-


What exactly it does-


Where exactly its used-


Kindly give the day to day basis example in short-
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 09-05-2007, 07:20 AM
amansundar amansundar is offline
D-Web Analyst
 
Join Date: May 2007
Posts: 322
amansundar is on a distinguished road
Default Re: socket programming

These are not simple questions I'm afraid. You need to learn socket programming thoroughly from a book, an online tutorial etc. Furthermore, you need to gain some experience in this area, not just the theory.
A quick "socket programminng" search on Google will certainly direct you to some tutorials.
__________________
cheers
Aman
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 09-05-2007, 10:57 PM
S.Vinothkumar S.Vinothkumar is offline
D-Web Genius
 
Join Date: May 2007
Posts: 1,061
S.Vinothkumar is on a distinguished road
Wink Re: socket programming

Visit this site for details of socket programming.

An Introduction to Socket Programming
__________________
S.VinothkumaR
Behind me is infinite power,
Before me is Endless Possibility,
Around me is Boundless Opportunity,
Why should I fear!
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #11 (permalink)  
Old 09-07-2007, 03:30 AM
Mramesh Mramesh is offline
D-Web Sr.Programmer
 
Join Date: Aug 2007
Location: Chennai
Posts: 106
Mramesh is on a distinguished road
Send a message via MSN to Mramesh
Question Re: socket programming

Hi

I'm new in pocket pc programming. i m developing chatting client in ppc.

I'm confusing to start my application. How to connect socket connection? I'm not a well known in socket programming...

Could anybody pls help...
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #12 (permalink)  
Old 09-07-2007, 04:18 AM
S.Vinothkumar S.Vinothkumar is offline
D-Web Genius
 
Join Date: May 2007
Posts: 1,061
S.Vinothkumar is on a distinguished road
Wink Re: socket programming

Hey Mramesh!

You want to connect socket programming in Compact Framework. right?

So you should have to know about TcpClient Class.

For more see the msdn link....
__________________
S.VinothkumaR
Behind me is infinite power,
Before me is Endless Possibility,
Around me is Boundless Opportunity,
Why should I fear!
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #13 (permalink)  
Old 09-07-2007, 04:31 AM
mobilegeek mobilegeek is offline
D-Web Analyst
 
Join Date: Jun 2007
Posts: 205
mobilegeek is on a distinguished road
Red face Re: socket programming

Establish a GPRS connection with TcpClient

NETCF's HttpWebRequest automatically sets up a GPRS connection for web requests/web services when a wired/wi-fi connection is not available. Therefore, when you do a web request or consume a web service, developers do not need special coding to handle the GPRS connection case. This does not apply to lower level socket classes like TcpClient and UdpClient. With these classes, you would need to use the Connection Manager APIs to establish/release the connections.

To allow users to more easily setup/release a GPRS connection, I have written a managed representation of the connection manager APIs that we need when we establish a GPRS connection with TcpClient:

Code:
 public class GPRSConnection
    {
        const int S_OK = 0;
        const uint CONNMGR_PARAM_GUIDDESTNET = 0x1;
        const uint CONNMGR_FLAG_PROXY_HTTP = 0x1;
        const uint CONNMGR_PRIORITY_USERINTERACTIVE = 0x08000;
        const uint INFINITE = 0xffffffff;
        const uint CONNMGR_STATUS_CONNECTED = 0x10;
        static Hashtable ht = new Hashtable();

        static GPRSConnection()
        {
            ManualResetEvent mre = new ManualResetEvent(false);
            mre.Handle = ConnMgrApiReadyEvent();
            mre.WaitOne();
            CloseHandle(mre.Handle);
        }

        ~GPRSConnection()
        {
            ReleaseAll();
        }

        public static bool Setup(Uri url)
        {
            return Setup(url.ToString());
        }

        public static bool Setup(string urlStr)
        {
            ConnectionInfo ci = new ConnectionInfo();
            IntPtr phConnection = IntPtr.Zero;
            uint status = 0;

            if (ht[urlStr] != null)
                return true;

            if (ConnMgrMapURL(urlStr, ref ci.guidDestNet, IntPtr.Zero) != S_OK)
                return false;
            
            ci.cbSize = (uint) Marshal.SizeOf(ci);
            ci.dwParams = CONNMGR_PARAM_GUIDDESTNET;
            ci.dwFlags = CONNMGR_FLAG_PROXY_HTTP;
            ci.dwPriority = CONNMGR_PRIORITY_USERINTERACTIVE;
            ci.bExclusive = 0;
            ci.bDisabled = 0;
            ci.hWnd = IntPtr.Zero;
            ci.uMsg = 0;
            ci.lParam = 0;

            if (ConnMgrEstablishConnectionSync(ref ci, ref phConnection, INFINITE, ref status) != S_OK &&
                status != CONNMGR_STATUS_CONNECTED)
                return false;

            ht[urlStr] = phConnection;
            return true;
        }

        public static bool Release(Uri url)
        {
            return Release(url.ToString());
        }

        public static bool Release(string urlStr)
        {
            return Release(urlStr, true);
        }

        private static bool Release(string urlStr, bool removeNode)
        {
            bool res = true;
            IntPtr ph = IntPtr.Zero;
            if (ht[urlStr] == null)
                return true;
            ph = (IntPtr)ht[urlStr];
            if (ConnMgrReleaseConnection(ph, 1) != S_OK)
                res = false;
            CloseHandle(ph);
            if (removeNode)
                ht.Remove(urlStr);
            return res;
        }

        public static void ReleaseAll()
        {
           foreach(DictionaryEntry de in ht)
           {
               Release((string)de.Key, false);
           }
           ht.Clear();
        }

        [StructLayout(LayoutKind.Sequential)]
        public struct ConnectionInfo
        {
            public uint cbSize;
            public uint dwParams;
            public uint dwFlags;
            public uint dwPriority;
            public int bExclusive;
            public int bDisabled;
            public Guid guidDestNet;
            public IntPtr hWnd;
            public uint uMsg;
            public uint lParam;
            public uint ulMaxCost;
            public uint ulMinRcvBw;
            public uint ulMaxConnLatency;
        }

        [DllImport("cellcore.dll")]
        private static extern int ConnMgrMapURL(string pwszURL, ref Guid pguid, IntPtr pdwIndex);

        [DllImport("cellcore.dll")]
        private static extern int ConnMgrEstablishConnectionSync(ref ConnectionInfo ci, ref IntPtr phConnection, uint dwTimeout, ref uint pdwStatus);

        [DllImport("cellcore.dll")]
        private static extern IntPtr ConnMgrApiReadyEvent();

        [DllImport("cellcore.dll")]
        private static extern int ConnMgrReleaseConnection(IntPtr hConnection, int bCache);

        [DllImport("coredll.dll")]
        private static extern int CloseHandle(IntPtr hObject);
    }
To use the GPRSConnection class, simply call the Setup method prior to creating a connection with the TcpClient() class. You may use the following sample as a reference to see how the class is used:


Code:
        public void DoTcpConnection()
        {
            string url = "www.msn.com";
            bool res = GPRSConnection.Setup("http://" + url + "/");
            if (res)
            {
                TcpClient tc = new TcpClient(url, 80);
                NetworkStream ns = tc.GetStream();
                byte[] buf = new byte[100];
                ns.Write(buf, 0, 100);
                tc.Client.Shutdown(SocketShutdown.Both);
                ns.Close();
                tc.Close();
                MessageBox.Show("Wrote 100 bytes");
            }
            else
            {
                MessageBox.Show("Connection establishment failed");
            }
        }
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #14 (permalink)  
Old 09-12-2007, 11:25 PM
raja raja is offline
D-Web Trainee
 
Join Date: May 2007
Posts: 34
raja is on a distinguished road
Question Re: socket programming

Hi all,

What are the steps for doing socket programming in Windows....I am trying to write a HTTP client using C which can get me a web page.

Please help
__________________
Raja. Myblog
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #15 (permalink)  
Old 09-12-2007, 11:49 PM
S.Vinothkumar S.Vinothkumar is offline
D-Web Genius
 
Join Date: May 2007
Posts: 1,061
S.Vinothkumar is on a distinguished road
Wink Re: socket programming

Hi there,

Very well, the answer is very simple, you need to know about port no. / name & it's usage, a little knowledge on protocols, i.e, TCP / UDP. Do a little research on google.com...........



Learn with my posts...
__________________
S.VinothkumaR
Behind me is infinite power,
Before me is Endless Possibility,
Around me is Boundless Opportunity,
Why should I fear!
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #16 (permalink)  
Old 07-20-2008, 02:23 AM
suzett suzett is offline
D-Web Trainee
 
Join Date: Jul 2008
Posts: 1
suzett is on a distinguished road
Default Re: socket programming

u just try TCP/IP socket the u will get idea about socket programming , then move to blootuth.

try this link.

VB.NET Socket Programming

suzett
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

LinkBacks (?)
LinkBack to this Thread: http://www.discussweb.com/vb-net-programming/3627-socket-programming.html
Posted By For Type Date
Untitled document This thread Refback 10-25-2007 03:44 AM

Similar Threads
Thread Thread Starter Forum Replies Last Post
ERROR 2002 (HY000): Can't connect to local MySQL server through socket Gopisoft Database Support 1 10-29-2007 02:07 AM
Socket programming in windows mobile 5.0 its support CAsyncSocket class? theone Windows Mobile 1 07-25-2007 12:24 AM
What is the difference between Windows programming and database programming? Arun VB.NET Programming 0 07-18-2007 07:58 AM
Socket Programming With PHP Jeyaseelansarc PHP Programming 0 05-16-2007 01:33 AM
XML Socket Servers programming in Flash Karpagarajan Flash Actionscript Programming 0 04-05-2007 03:00 AM


All times are GMT -7. The time now is 12:35 PM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.

SEO by vBSEO 3.0.0