请将下面的SourceCode从JB语言转换成C#语言(本人第一次接触C#)

hs981350 2005-11-01 04:04:53
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;
}
...全文
99 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
miaoliujun 2005-11-02
  • 打赏
  • 举报
回复
JB不是语言

最好的办法,是你去C#问问怎么实现这个功能
或者自己去查找HELP,自力更生
hs981350 2005-11-02
  • 打赏
  • 举报
回复
UP
hs981350 2005-11-01
  • 打赏
  • 举报
回复
private InputStream m_socketInputStream;
private OutputStream m_socketOutputStream;
上面两句在C#中要怎样表示?
poboy 2005-11-01
  • 打赏
  • 举报
回复
楼主慢慢玩 吧?
爱莫能助呀

友情 up
hs981350 2005-11-01
  • 打赏
  • 举报
回复
快点呀,在线等。
hs981350 2005-11-01
  • 打赏
  • 举报
回复
没有人会吗?100分呀:-)

50,504

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧