Using TcpClient with Modem

G

Guest

Hi everybody,

I am still learning how sockets, TcpClient and TcpListener work, in order
that both sides to send and receive data, both sides must have a socket or
TcpListener and a TcpListener right? Is there a possible way to say just have
a client side TcpClient application to send a message to remote server like
sending a text file?

Do TcpClient requires a Internet connection to connect say to remote
server? So, to connect to a VPN network(remote server), I need to establish
internet connection like using RAS. Right? How do you programatically create
connection using a local USB port with a GPRS modem? Using Sockets or
TCPClient will be enough to do that? Please provide me with info on these
questions.

Is there anybody knows how to do this? Thanks.

den2005
 
T

tdavisjr

USB is based on serial communications. You will need use some code that
connects to a serial port. Also, USB does not directly map to a COM
port so it would be good to find some software that is able to
virtualize a COM port from a USB device.

The .NET 2.0 now have classes that can connect to a serial port and
communicate with it.
 
G

Guest

Thanks for reply, tdavisjr.

I am using .Net Framework ver 1.1. What are these classes you are mentioning
that does USB port connection?

den2005
 
T

tdavisjr

Sorry, these classes are only apart of .NET 2.0. If you are using 1.1
then you probably would have to seek a 3rd party component.
 
G

Guest

Thanks for link tdavisjr.

Is there a way to use this SerialPort Class in Visula Studio .Net 2003
Version? I have installed the .Net Framework 2.0 at my computer. But seems
unable to call this class in code editor window.

den2005
 
T

tdavisjr

Nope. If you don't have VS 2005 then try downloading the Free Express
versions. It will allow you to at least play around with some of the
..NET 2.0 classes. But you can't compile 2.0 classes with VS.NET 2003
 
G

Guest

Thanks for reply, tdavisjr.

Right now, I stick with ver 1.1. Do you know anything about these api I
found which deals with serial ports communication.

Do you or anybody knows how to use this following api? Is there can be
definite and simple sample how to use them to say establish serial port
connection in order to connect to gprs modem to send and recieve? Right now,
this is approach I am pursuing to solve this problem. Info would be great??
Thanks

[DllImport("kernel32.dll")]

private static extern Boolean GetCommProperties(IntPtr hFile, out COMMPROP
cp);

[DllImport("kernel32.dll")]

private static extern Boolean GetCommModemStatus(IntPtr hFile, out UInt32
lpModemStat);

[DllImport("kernel32.dll")]

private static extern Boolean GetCommState(IntPtr hFile, ref DCB lpDCB);

[DllImport("kernel32.dll")]

private static extern Boolean SetCommState(IntPtr hFile, [In] ref DCB lpDCB);

[DllImport("kernel32.dll", SetLastError=true)]

private static extern IntPtr CreateFile(String lpFileName, UInt32
dwDesiredAccess, UInt32 dwShareMode, IntPtr lpSecurityAttributes, UInt32
dwCreationDisposition, UInt32 dwFlagsAndAttributes, IntPtr hTemplateFile);

[DllImport("kernel32.dll")]

private static extern Boolean CloseHandle(IntPtr hObject);

[DllImport("kernel32.dll", SetLastError=true)]

private static extern Boolean ReadFile(IntPtr hFile, [Out] Byte[] lpBuffer,
UInt32 nNumberOfBytesToRead, out UInt32 nNumberOfBytesRead, IntPtr
lpOverlapped);

[DllImport("kernel32.dll", SetLastError=true)]

private static extern Boolean WriteFile(IntPtr fFile, Byte[] lpBuffer,
UInt32 nNumberOfBytesToWrite, out UInt32 lpNumberOfBytesWritten, IntPtr
lpOverlapped);

[DllImport("kernel32.dll")]

private static extern Boolean CancelIo(IntPtr hFile);

[DllImport("kernel32.dll")]

private static extern Boolean TransmitCommChar(IntPtr hFile, Byte cChar);

[DllImport("kernel32.dll")]

internal static extern Boolean SetupComm(IntPtr hFile, UInt32 dwInQueue,
UInt32 dwOutQueue);

den2005
 
T

tdavisjr

These are Windows API calls. In VB and C# this is called Platform
Invoke. This allows you to tap into the Windows Operating System by
calling functions that are found in a operating system dll. I have not
done this, so good luck
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top