Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using IRdA with Socket (on laptop, so no Compact Framework)

Status
Not open for further replies.

ProgrammersHell

Programmer
Oct 2, 2003
6
NL
I could really use some help controlling the IrDA port on my laptop. I want to create some kind of server that can accept connections from PocketPC's. I cant use the IrDA Client and IrDALister classes, because they only excist in the .Net Compact framework. This is what i have so far:

using System;
using System.Net;
using System.Net.Sockets;

class TestIR
{
//serv is the accepting socket
private Socket serv, conn;
EndPoint ep, irdaEp;
public TestIR()
{
try
{
serv = new Socket(AddressFamily.Irda, SocketType.Stream, ProtocolType.Unspecified);
ep = new IPEndPoint(0,0);
irdaEp = (EndPoint)ep.Create(new SocketAddress(AddressFamily.Irda));
serv.Bind(ep);
conn = serv.Accept();
Console.WriteLine("Availability: {0}",conn.Available);
}catch(SocketException e)
{
Console.WriteLine("Error {0} found with message {1}",e.ErrorCode, e.Message);
}
}

public static void Main()
{
TestIR ir = new TestIR();
}
}

The problem is that the socket has to be bound to an EndPoint (serv.Bind(ep)). I found out that you cant use an IPEndPoint (gives some kind of pointer error), and IrDAEndPoint isn't available. Also, you cant make an instance of EndPoint (abstract).
In the above code, the error says that i cant create an EndPoint of the Irda AddressFamily with an IPEndPoint.

The only other solution i know is the more low-level WinSock2 programming, but i want to try it in C# first.

I hope someone can help me.
 
>> ep = new IPEndPoint(0,0);

That makes no sense. At the very least you have to supply a port if you are going to accept connections.

Also did you first try using the System.Net.Sockets.TcpListener class. The overview of the class contains sample code for a server application.


-pete
 
Hi palbano, thanks for your fast reaction.

About your first remark:
>> ep = new IPEndPoint(0,0);

The IPEndPoint ep shouldn't be used. I now see that i used ep to bind the socket, that was a mistake i made. Ep should only be used to create a new EndPoint with a SocketAddress (contains a Irda AddressFamily enumerator), so the values of the IPEndPoint ep shouldn't matter.

About the TCPListener: As far as i know IrDA doesn't use TCP, therefore i can't use it. And, with the TCPListener i can't open the IrDA port. I need to open a socket and bind an endpoint to it that supports Irda.
 
I think i found the solution, haven't tested it yet. I found the source code of the IRdAEndPoint class, which i just parsed in my program (it needed some editing, but not too difficult). I don't get any compiler errors, but i still need to test the communication with a pda.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top