请将下面的SourceCode从JB语言转换成C#语言(本人第一次接触C#)
package SmsJApp;
import java.net.*;
import java.io.*;
import javax.swing.*;
import java.awt.*;
import java.lang.*;
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2005</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/
public class SmsJApp {
private Socket m_socket;
private InputStream m_socketInputStream;
private OutputStream m_socketOutputStream;
private String m_strUserID;
private String m_strPassword;
private String m_strSvrIP;
private int m_nSvrPort;
private String m_strRecvIP;
private int m_nRecvPort;
private int m_nTimeout;
private boolean m_bLogin = false;
private static SmsJApp c_SmsJApp = new SmsJApp();
private SmsJApp() {
}
public static SmsJApp getInstance()
{
if(c_SmsJApp.m_bLogin == false)
{
if(c_SmsJApp.OpenSmsSvr("websvr", "websvr", "192.168.0.13", 7001, "", 0, 30000) < 0)
{
System.out.println("Fail");
}
else
{
System.out.println("Success");
}
}
return c_SmsJApp;
}
//登录
public synchronized int OpenSmsSvr(String strUserID,
String strPassword,
String strSvrIP,
int nSvrPort,
String strRecvIP,
int nRecvPort,
int nTimeout)
{
try
{
m_strUserID = new String(strUserID);
m_strPassword = new String(strPassword);
m_strSvrIP = new String(strSvrIP);
m_nSvrPort = nSvrPort;
m_strRecvIP = new String(strRecvIP);
m_nRecvPort = nRecvPort;
m_nTimeout = nTimeout;
if(m_bLogin)
{
CloseSmsSvc();
}
if(!ConnectSvr())
{
return -1;
}
// String strHello = "Hello!";
// m_socketOutputStream.write(0x12345678);
// m_socketOutputStream.write(strHello.getBytes());
// m_socketOutputStream.flush();
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null,null,"TEST TITLE",JOptionPane.ERROR_MESSAGE);
return -1;
}
return 0;
}
private synchronized boolean ConnectSvr()
{
try{
//网络连接
m_socket = new Socket();
InetSocketAddress inAddr = new InetSocketAddress(m_strSvrIP, m_nSvrPort);
m_socket.connect(inAddr, m_nTimeout);
m_socketOutputStream = m_socket.getOutputStream();
m_socketInputStream = m_socket.getInputStream();
m_socket.setSoTimeout(30000); //数据超时
//用户登录
String strLogin = new String("");
strLogin += "<?xml version=\"1.0\"?>";
strLogin += "<ClnLogin>";
strLogin += "<UserID>" + m_strUserID + "</UserID>";
strLogin += "<Password>" + m_strPassword + "</Password>";
strLogin += "<IP>" + m_strRecvIP + "</IP>";
strLogin += "<Port>" + m_nRecvPort + "</Port>";
strLogin += "</ClnLogin>";
m_socketOutputStream.write(strLogin.getBytes());
m_socketOutputStream.flush();
//recv
byte szBuf[] = new byte[4096];
int nRead = 0;
// try
{
nRead = m_socketInputStream.read(szBuf);
}
// catch(Exception eN)
// {
// }
String strLoginACK = new String(szBuf, 0, nRead);
int nPos = strLoginACK.indexOf("<ClnLoginACK>");
int nEnd = strLoginACK.indexOf("</ClnLoginACK>");
String str = new String("");
String strV = new String("");
if(nPos > 0 && nEnd > 0)
{
str = "<Result>";
int n1 = strLoginACK.indexOf(str, nPos) + str.length();
str = "</Result>";
int n2 = strLoginACK.indexOf(str, nPos);
if(n1>0 && n2>0)
{
strV = strLoginACK.substring(n1, n2);
int iResult = Integer.parseInt(strV);
if(iResult >= 0)
{
m_bLogin = true;
}
else{
return false;
}
}
else{
return false;
}
}
else{
return false;
}
// JLabel lblMessage = new JLabel(strLoginACK);
// lblMessage.setFont(new Font("宋休",Font.BOLD,12));
// JOptionPane.showMessageDialog(null,lblMessage,"TEST TITLE",JOptionPane.ERROR_MESSAGE);
}
catch(Exception e){
try
{
m_socket.close();
}
catch(Exception e2)
{
}
return false;
}
return true;
}
private synchronized boolean ReConnecSvr()
{
try{
m_socket.close();
}
catch(Exception e){
}
return ConnectSvr();
}
//注销
public synchronized int CloseSmsSvc()
{
int iRet = 0;
try
{
m_bLogin = false;
//用户登录
String strLogout = new String("");
strLogout += "<?xml version=\"1.0\"?>";
strLogout += "<ClnLogout>";
strLogout += "<UserID>" + m_strUserID + "</UserID>";
strLogout += "<Password>" + m_strPassword + "</Password>";
strLogout += "</ClnLogout>";
m_socketOutputStream.write(strLogout.getBytes());
m_socketOutputStream.flush();
//recv
byte szBuf[] = new byte[4096];
int nRead = m_socketInputStream.read(szBuf);
String strLogoutACK = new String(szBuf, 0, nRead);
int nPos = strLogoutACK.indexOf("<ClnLogoutACK>");
int nEnd = strLogoutACK.indexOf("</ClnLogoutACK>");
String str = new String("");
String strV = new String("");
if(nPos > 0 && nEnd > 0)
{
str = "<Result>";
int n1 = strLogoutACK.indexOf(str, nPos) + str.length();
str = "</Result>";
int n2 = strLogoutACK.indexOf(str, nPos);
if(n1>0 && n2>0)
{
strV = strLogoutACK.substring(n1, n2);
int iResult = Integer.parseInt(strV);
if(iResult >= 0)
{
}
else{
iRet = -1;
}
}
else{
iRet = -1;
}
}
else{
iRet = -1;
}
m_socketOutputStream.close();
m_socketInputStream.close();
m_socket.close();
}
catch(Exception e)
{
try
{
m_socket.close();
}
catch(Exception e2){
}
iRet = -1;
}
return iRet;
}