java Socket??C#????????????????????????
???????????? ???????[ 2012/12/13 9:53:40 ] ????????
???????????????????????????????????????java??.NET?????????????????????????????
????????????java????????????????C#???????????????TCP??Socket???????????????????????小?????????????????????????????????????椋�?????????????????????????????泻?????????????????椋�????????????????????????????????????
??????????????????????????C#??java???????????????????????????????????????????????????????????????????????????邪?????
???????????????java?????????????????
import java.net.*;
import java.io.*;
public class TCPCline{
public static void main(String[] args) throws Exception{
try{
//?????IP????????????IP?????????????????
Socket s = new Socket("IP???"?????);
OutputStream os = s.getOutputStream();
DataOutputStream dos = new DataOutputStream(os);
String sendStr = "????hello";
//???????getBytes?????械?"UTF-8"
byte[] bs = sendStr.getBytes("UTF-8");
//??????????write??????????writeUTF????????????????????java????????????娼�????
dos.write(bs??0??bs.length);
//??????????????????????????????????????????????????????????????????????????
//dos.close();
//s.close();
}catch(ConnectException connExc){
connExc.printStackTrace();
}catch(IOException e){
e.printStackTrace();
}
}
}
????C#???????????????????????锟�???????????????????????????TCPServer??
?????????????????????????????????????????????????????
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System;
namespace TCPServer
{
/// <summary>
/// ?????????
/// </summary>
public class LogHelper
{
public static readonly object objLock = new object();
/// <summary>
/// ??????写??.log?????
/// </summary>
/// <param name="msg">???????</param>
/// <param name="ex">??</param>
public static void Err(string msg?? Exception ex)
{
string s = "";
if (ex != null)
{
s = "err:" + msg + ":" + ex.Message;
}
else
{
s = msg ;
}
//???????????log?????
string filename = AppDomain.CurrentDomain.BaseDirectory + "log/" + Convert.ToString(getUnixTime()) + ".log";
lock (objLock)
{
using (System.IO.StreamWriter sw = new System.IO.StreamWriter(filename?? true))
{
sw.WriteLine(s);
if (ex != null)
{
sw.WriteLine(ex.StackTrace);
}
sw.WriteLine("time:" + DateTime.Now.ToString());
sw.WriteLine("----------------------------------");
}
}
}
??????
???路???
??????????????????
2023/3/23 14:23:39???写?貌??????????
2023/3/22 16:17:39????????????????????些??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???路???????路
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11